我正在尝试使用 wx.Choice 组件来归档一个简单的应用程序。
这个想法是,wx.Choice 中列出了许多项目,每个项目都会触发一个独特的功能。
我的第一个代码版本是:
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, 0, 'wxPython pull-down choice', size = (400, 300))
panel_select_model= wx.Panel(self, -1)
model_list = ['Test_A', 'Test_B']
self._model_type = None
self._stat_tex = wx.StaticText(panel_select_model, 1, "Select Model Type:", (15, 20))
self._droplist = wx.Choice(panel_select_model, 2, (150, 18), choices = model_list)
""" Bind A Panel """
self._droplist.SetSelection(0)
self._droplist.Bind(wx.EVT_CHOICE, self.Test_A_click)
但事实证明,下拉列表中的两项将触发相同的功能(我希望Test_A
会触发该功能并且Test_B
什么也不做)。所以我尝试绑定Test_B
到另一种方法Test_B_click
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, 0, 'wxPython pull-down choice', size = (400, 300))
panel_select_model= wx.Panel(self, -1)
model_list = ['Test_A', 'Test_B']
self._model_type = None
self._stat_tex = wx.StaticText(panel_select_model, 1, "Select Model Type:", (15, 20))
self._droplist = wx.Choice(panel_select_model, 2, (150, 18), choices = model_list)
""" Bind A Panel """
self._droplist.SetSelection(0)
self._droplist.Bind(wx.EVT_CHOICE, self.Test_A_click)
""" Bind B Panel """
self._droplist.SetSelection(1)
self._droplist.Bind(wx.EVT_CHOICE, self.Test_B_click)
上面的代码显示了一个主框架,其中有一个下拉列表和下拉列表中的两个项目。但是,当我单击这两个项目中的任何一个时,不再触发任何功能。
那么,我该如何实现我的目标:将不同的函数绑定到 wx.Choice 组件中的每个项目,并让它们正确触发函数。
谢谢。