Drop down menu wxPython:wx.Choice事件EVT_Choice在应用程序启动时触发,但在选择更改时不触发

Drop down menu wxPython:wx.Choice事件EVT_Choice在应用程序启动时触发,但在选择更改时不触发,drop-down-menu,event-handling,wxwidgets,wxpython,Drop Down Menu,Event Handling,Wxwidgets,Wxpython,我使用以下类创建wx.Choice: class LanguageSelector(wx.Choice): """Class for the creation of a language selector.""" def __init__(self, parent): """Create a language selector, default to current language and bind options to localisation methods.""" sup

我使用以下类创建wx.Choice:

class LanguageSelector(wx.Choice):
"""Class for the creation of a language selector."""
def __init__(self, parent):
    """Create a language selector, default to current language and bind options to localisation methods."""
    super().__init__(parent=parent, choices=self.list_available_languages())

    self.SetSelection(self.FindString(loc.o))  # Set current language as default option.

    self.Bind(wx.EVT_CHOICE, self.on_choice())  # This is the problem.

def on_choice(self):
    print("on_choice was triggered. Selected item is: " + str(self.GetSelection()))
    selection = self.GetString(self.GetSelection())
    print("Converted selection is: " + selection)
    loc.change(selection)
不要介意“loc”项:这是我用来处理本地化的东西。
self.list\u available\u languages()是一个静态方法,它用项填充选项

现在的问题是:当我运行应用程序时,打印消息会立即打印并显示默认选择(这是我希望不会发生的事情,但并不重要),但是当我尝试在“选择”下拉列表中选择各种选项时,无论选择哪一个,都不会触发任何事件


我更喜欢不必使用按钮捕捉选择,并在选择更改时正确执行。我不明白我做错了什么。

您正在调用处理程序,而不是绑定它。必须将函数而不是调用此函数的结果传递给
Bind()
。只需删除括号即可解决此问题。

python和wxPython的哪个版本?什么操作系统?您是否自己编译了wxPython,从wxPython.org下载了正式版本,或者从存储库安装了它?最后,你能在wxPython演示中重现它吗?我有python 3.6 32位版本,wxPython版本是4.0.0b2,我按照wxPython网站上的说明随pip一起安装。我使用的是Windows 10,最后,我没有尝试演示。Franky我甚至不知道应该下载哪个版本,因为我的操作系统是64位的,但我有一个32位的python版本。顺便说一句,我检测bug的方法是通过PyCharm运行程序。我怀疑这可能与此相关,所以我将在这里报告它,以防它有助于识别问题:我继续开发代码的另一部分,最后使用了另一个绑定到事件,这次是wx.EVT_LISTBOX。现在,从发生的情况来看,当应用程序运行时(这显然不应该发生),事件似乎会自动触发一次,而当我执行应该触发它的操作时,事件则不会自动触发:我在上面的问题主体中选择的wx.EVT_也会发生什么。这里到底是什么原因?