class MonitorBox(wx.StaticBoxSizer):
def __init__(self, monitors, pins, devices, *args, **kw):
super().__init__(*args, **kw)
self.monitors = monitors
self.pin_choices = pins
self.dev_choices = devices
self.InitUI()
def InitUI(self):
monList = wx.FlexGridSizer(cols=4, vgap=5, hgap=5)
add_monitor = wx.Button(self, wx.ID_ANY, "Add Monitor")
add_monitor.Bind(wx.EVT_BUTTON, self.on_add_button)
# create list headings
nametxt = wx.StaticText(self, wx.ID_ANY, "Name:")
devtxt = wx.StaticText(self, wx.ID_ANY, "Device:")
pintxt = wx.StaticText(self, wx.ID_ANY, "Pin:")
blnktxt = wx.StaticText(self, wx.ID_ANY, "")
# Add Headings to sizer
monList.AddMany([nametxt, devtxt, pintxt, blnktxt])
self.monitor_rows = {} # dictionary to store references to all the widgets
# Create a row for each item in the mons dictionary
for monitor, dev in self.mons.items():
del_mon_button = wx.Button(self, wx.ID_ANY, '-', name=monitor, style=wx.BU_EXACTFIT)
del_mon_button.Bind(wx.EVT_BUTTON, self.on_del_monitor)
mon_name = wx.TextCtrl(self, wx.ID_ANY, monitor,
style=wx.TE_PROCESS_ENTER,
name=monitor)
dev_name = wx.ComboBox(self, wx.ID_ANY, choices=self.dev_choices,
style=wx.CB_READONLY, value=dev[0],
name=monitor)
pin_name = wx.ComboBox(self, wx.ID_ANY, choices=self.pin_choices[dev[0]],
style=wx.CB_READONLY, value=dev[1],
name=monitor)
dev_name.Bind(wx.EVT_COMBOBOX, self.on_dev_choice)
pin_name.Bind(wx.EVT_COMBOBOX, self.on_pin_choice)
self.monitor_rows[monitor] = [mon_name, dev_name, pin_name, del_mon_button]
monList.AddMany(self.monitor_rows[monitor])
# TODO: make sure all the combo boxes are the same size
self.monList = monList
self.Add(monList, 1, wx.ALL, 5)
self.Add(add_monitor, 0, wx.ALL, 5)
add_monitor = wx.Button(self, wx.ID_ANY, "Add Monitor")
TypeError: Button(): arguments did not match any overloaded call:
overload 1: too many arguments
overload 2: argument 1 has unexpected type 'MonitorBox'
我相信这是因为我试图使用我的自定义类作为它内部所有小部件的父类,但是我不明白为什么会发生这种情况?
我是非常新的创建图形用户界面(这是我的第一个项目),但我目前正在经历和修复所有的过程中提到家长等,所以我很难知道正确的搜索条件,看看是否有其他人有这个问题。
我原来的代码只是
InitUI(self)
从main调用的函数wx.框架将monBox创建为一个StaticBoxSizer,它直接添加了所有的子部件。正如一开始提到的,我之所以要将其拆分,是因为有许多事件处理程序和由这个面板创建的其他dialog框,我想将它们保存在一个单独的文件中,以帮助保持代码可读性。