wxPython: Threading GUI --> Using Custom Event Handler

后端 未结 3 1198
孤街浪徒
孤街浪徒 2021-02-06 18:41

I am trying to learn how to run a thread off the main GUI app to do my serial port sending/receiving while keeping my GUI alive. My best Googling attempts have landed me at the

3条回答
  •  一个人的身影
    2021-02-06 19:23

    That's the old style of defining custom events. See the migration guide for more information.

    Taken from the migration guide:

    If you create your own custom event types and EVT_* functions, and you want to be able to use them with the Bind method above then you should change your EVT_* to be an instance of wx.PyEventBinder instead of a function. For example, if you used to have something like this:

    myCustomEventType = wxNewEventType()
    def EVT_MY_CUSTOM_EVENT(win, id, func):
        win.Connect(id, -1, myCustomEventType, func)
    

    Change it like so:

    myCustomEventType = wx.NewEventType()
    EVT_MY_CUSTOM_EVENT = wx.PyEventBinder(myCustomEventType, 1)
    

    Here is another post that I made with a couple of example programs that do exactly what you are looking for.

提交回复
热议问题