python - 使用 wx.DC 设置背景颜色的更好方法

标签 python wxpython wxwidgets

现在,我是这样设置背景颜色的,

dc.DrawRectangle(0,0,width,height)

你知道设置背景颜色的更好方法吗?

http://wxpython.org/docs/api/wx.DC-class.html

最佳答案

如果您已经在 wx.DC 上绘制以绘制窗口的其余内容,那么最好的方法是设置背景画笔,然后清除 DC。像这样:

def OnPaint(self, event):
    dc= wx.PaintDC(self)
    dc.SetBackground(wx.Brush(someColour))
    dc.Clear()
    # other drawing stuff...

如果您使用窗口的 SetBackgroundColour 方法设置颜色,那么您可以使用它来代替一些固定的颜色值,如下所示:

def OnPaint(self, event):
    dc= wx.PaintDC(self)
    dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
    dc.Clear()
    # other drawing stuff...

关于python - 使用 wx.DC 设置背景颜色的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11766759/

相关文章:

C++串行连接

ubuntu - wxWidgets安装后找不到wxWebView

python - 基于 WSGI 的 Python Web 框架

python - Pandas 数据框可对多列和要列出的值进行字典

python - 使用 twisted.enterprise.adbapi 处理 'database is locked' 错误的正确和最佳方法

python - WxPython 问题 : Subpanels within a Notebook Panel

multithreading - 将控制台数据从进程输出到wxwidgets中的gui

python - 关闭 PyQt 窗口后如何执行更多代码?

python - wxpython中的派生面板类

python - wxPython。如何使静态尺寸面板居中?