wxPython: Calling an event manually

后端 未结 6 1730
青春惊慌失措
青春惊慌失措 2020-12-02 17:14

How can I call a specific event manually from my own code?

6条回答
  •  悲&欢浪女
    2020-12-02 17:55

    There's a simple, straightforward way to do it with recent versions of wxPython (see http://wiki.wxpython.org/CustomEventClasses):

       # create event class
       import wx.lib.newevent
       SomeNewEvent, EVT_SOME_NEW_EVENT = wx.lib.newevent.NewEvent()
    
       # post it, with arbitrary data attached
       wx.PostEvent(target, SomeNewEvent(attr1=foo, attr2=bar))
    
       # bind it as usual
       target.Bind(EVT_SOME_NEW_EVENT, target.handler)
    

提交回复
热议问题