How to fix "TypeError: Sizer.Add(): arguments did not match any overloaded call:" while trying to set background colour

How to fix "TypeError: Sizer.Add(): arguments did not match any overloaded call:" while trying to set background colour

我正在使用 wxpython 构建一个 GUI,它包含一个类似于彩色热图的 button/statictext 网格(25 x 25 网格)

我在尝试为每个人设置自定义颜色时遇到错误statictext/button

我有一个 statictext/button 的工作数组,但我无法使用以下代码为单个 statictext/button 设置自定义颜色。

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'

你不能那样做。
您可以做的是像这样访问 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)