在 wxPython 中生成自定义的 CommandEvent [英] Generate a custom CommandEvent in wxPython
本文介绍了在 wxPython 中生成自定义的 CommandEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的顶级窗口需要知道自定义控件的内部状态何时发生变化,以便它可以更新 GUI 的各个其他部分.如何在控件中生成自定义事件,以便它可以传播并由顶级窗口处理?
My top-level window needs to know when the internal state of a custom control changes so it can update various other parts of the GUI. How do I generate a custom event in the control, so it can propagate and be handled by the top-level window?
推荐答案
我知道这是一个老问题,但是在 wxPython 中有一种更新的、稍微好一点的方法.转述自 http://wiki.wxpython.org/CustomEventClasses 及以上内容:
I know this is an old question, but there is a newer, slightly nicer, way to do this in wxPython. Paraphrased from http://wiki.wxpython.org/CustomEventClasses and the above:
定义事件:
import wx.lib.newevent
QuantityChangedEvent, EVT_QUANTITY_CHANGED = wx.lib.newevent.NewCommandEvent()
要生成事件:
event = QuantityChangedEvent(self.GetId())
self.GetEventHandler().ProcessEvent(event)
# or ...
#wx.PostEvent(self, event)
绑定事件保持不变.
这篇关于在 wxPython 中生成自定义的 CommandEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文