תÌû£º
import sys
from wxPython.wx import *
from wxPython.lib import newevent
DispatchEvent, EVT_DISPATCH = newevent.NewEvent()
class GenericDispatchMixin:
def __init__(self):
EVT_DISPATCH(self, self.OnDispatchEvent)
def OnDispatchEvent(self, event):
event.method(*event.arguments)
def ThreadSafeDispatch(self, method, *arguments):
wxPostEvent(self, DispatchEvent(method = method, arguments = arguments))
import wx
import time
import threading
import Queue
import traceback
import sys
from GenericDispatch import GenericDispatchMixin
class MainApp(wx.App):
def OnInit(self):
self.frame = MainFrame()
self.frame.Show(True)
self.SetTopWindow(self.frame)
return True
class MainFrame(wx.Frame, GenericDispatchMixin):
def __init__(self):
wx.Frame.__init__(self, None, -1, u¡¯³¤ÔËÐвâÊÔ¡¯)
GenericDispatchMixin.__init__(self)
box = wx.BoxSizer(wx.HORIZONTAL)
self.ID_BTN = wx.NewId()
self.btn = wx.Button(self, self.ID_BTN, u¡¯¿ªÊ¼¡¯, size=(60, 22))
box.Add(self.btn, 0, wx.ALIGN_CENTRE|wx.ALL, 0)