wxPython – 改变工具栏颜色 wx.ToolBar
在本文中,我们将学习更改工具栏的颜色。我们将简单地使用 SetBackgroundColour()函数来执行此操作。 SetBackgroundColour() 设置窗口的背景颜色。它接受一个 wx.Colour 参数,即用作背景颜色的颜色。
Syntax: wx.ToolBar.SetBackgroundColour(self, colour)
Parameters:
Parameter | Input Type | Description |
---|---|---|
colour | wx.Colour | The colour to be used as the background colour |
Return Type: bool
Returns: True if the colour was really changed, False if it was already set to this colour and nothing was done.
代码示例:
import wx
class Example(wx.Frame):
global count
count = 0;
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
pnl = wx.Panel(self)
self.toolbar = self.CreateToolBar()
# Add tools to toolbar
ptool = self.toolbar.AddTool(12, 'oneTool',
wx.Bitmap('right.png'),
wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
qtool = self.toolbar.AddTool(12, 'oneTool', wx.Bitmap('wrong.png'),
wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
# change background colour of toolbar
self.toolbar.SetBackgroundColour((255, 200, 50, 255))
self.toolbar.Realize()
self.SetSize((350, 250))
self.SetTitle('Control')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口: