wxPython:在程序启动时自动执行事件函数
我的代码中有一个组合框事件:
self.combobox1.Bind(wx.EVT_COMBOBOX, self.onActionCombobox1)
它执行该函数
def onActionCombobox1(self, event):
有没有办法在每次启动程序时自动执行该函数? 我这样尝试:
self.onActionCombobox1(event)
但它说 未定义的变量:事件
There's a combobox event in my code:
self.combobox1.Bind(wx.EVT_COMBOBOX, self.onActionCombobox1)
It executes the function
def onActionCombobox1(self, event):
Is there a way to execute this function automatically everytime when I start my program?
I tried it like this:
self.onActionCombobox1(event)
but it says Undefined variable: event
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不使用您想要执行的事件变量:
在类的 __init__ 方法中设置,将在类实例化时执行该方法(不一定等同于 wxPython 中的程序启动您可以拥有可以在运行时动态创建的窗口/小部件,您可以在实例化它之前从类中调用该方法,但方法操作不必与任何小部件状态或行为相关,因为它们还不存在。在这种情况下也许该方法应该最好写成一个独立的函数)。
if you do not make use of the event variable you want to do:
This, set in the
__init__
method of your class, will execute the method at class instantiation (not necessarily equivalent to program startup as in wxPython you can have windows/widgets that can be created dynamically at run time. You could call the method from the class before instantiating it but then method actions have not to be related with any widget state or behavior as they do not exist yet. Anyway, in that case maybe the method should be written better as an independent function).