选择列表框项时触发的事件

2024-04-25 23:14:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我像这样初始化wx.ListBox

mylistbox = wx.ListBox(self, style=wx.LB_SINGLE)
mylistbox.Bind(wx.EVT_LISTBOX, self.OnEventListBox)
# some other things (append some items to the list)
mylistbox.SetSelection(5)

我还有:

^{pr2}$

如何使初始化中的命令mylistbox.SetSelection(5)紧跟着OnEventListBox的调用?

备注:似乎SetSelection()不会生成wx.EVT_列表框自动地。在


Tags: selfbindstylesomeevtwxotherthings
1条回答
网友
1楼 · 发布于 2024-04-25 23:14:34

来自the documentation

Note that [SetSelection] does not cause any command events to be emitted...

这是有目的的,这样在您尝试设置UI时不会触发所有事件。您只需手动调用OnEventListBox来获得所需的功能。在

更好的是,如果您在init上执行的操作不需要事件,可以将初始化提取到一个单独的函数中,然后在initOnEventListBox中调用该函数。在

相关问题 更多 >