我正在使用wxpython构建GUI,该GUI由类似于彩色热图的按钮/静态文本网格(25 x 25网格)组成
尝试为每个单独的静态文本/按钮设置自定义颜色时遇到错误
我有一组静态文本/按钮,并且无法使用以下代码为各个静态文本/按钮设置自定义颜色。
sizer = wx.GridSizer(25, 25, 0, 0)
sizer.AddMany([wx.StaticText(panel,size=(30,30), label='A1',style=wx.ALIGN_CENTER).SetBackgroundColour((255,0,0)),
wx.StaticText(panel,size=(30,30), label='A2',style=wx.ALIGN_CENTER).SetBackgroundColour((255,255,0)),
我期望我可以使用SetBackgroundColor()将自定义背景色设置为不同的静态文本和按钮
我遇到以下错误:
TypeError: Sizer.Add(): arguments did not match any overloaded call:
overload 1: argument 1 has unexpected type 'bool'
overload 2: argument 1 has unexpected type 'bool'
overload 3: argument 1 has unexpected type 'bool'
overload 4: argument 1 has unexpected type 'bool'
overload 5: not enough arguments
overload 6: not enough arguments
overload 7: argument 1 has unexpected type 'bool'
overload 8: argument 1 has unexpected type 'bool'
overload 9: argument 1 has unexpected type 'bool'
答案 0 :(得分:0)
你不能那样做。
您可以做的就是像这样访问panel
中的所有子级。
children = panel.GetChildren()
for child in children:
if child.GetClassName() == "wxToggleButton":
child.SetForegroundColour(wx.RED)
或者稍长一些,在sizer
children = sizer.GetChildren()
for child in children:
x = child.GetWindow()
if x.GetClassName() == "wxToggleButton":
x.SetForegroundColour(wx.RED)