Python-Uso diwx.PostEvent事件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python-Uso diwx.PostEvent事件相关的知识,希望对你有一定的参考价值。

  1. import wx, thread, time
  2.  
  3. def EVT_RESULT(win,func):
  4. win.Connect(-1,-1,111,func)
  5.  
  6. class RESULT(wx.PyEvent):
  7.  
  8. def __init__(self, data):
  9.  
  10. wx.PyEvent.__init__(self)
  11.  
  12. self.SetEventType(111)
  13. self.data = data
  14.  
  15. class Main_Frame(wx.Frame):
  16.  
  17. def __init__(self, parent=None, id=-1, title='Example PostEvent...'):
  18.  
  19. self.ID_S = wx.NewId()
  20. self.ID_ST = wx.NewId()
  21.  
  22. wx.Frame.__init__(self, parent, id, title)
  23.  
  24. self.CenterOnScreen()
  25. self.Show()
  26.  
  27. self._panel = wx.Panel(parent=self, id=-1)
  28.  
  29. self._bu = wx.Button(parent=self._panel, id=self.ID_S, label='OK', size=(100, 100))
  30. self.Bind(wx.EVT_BUTTON, self.OnStart, id=self.ID_S)
  31.  
  32. self._bo = wx.Button(parent=self._panel, id=self.ID_ST, label='KO',pos=(0, 200), size=(100, 100))
  33.  
  34. self.Bind(wx.EVT_BUTTON, self.OnStop, id=self.ID_ST)
  35.  
  36. EVT_RESULT(self, self.OnR)
  37.  
  38. self.CreateStatusBar()
  39.  
  40. def OnR(self, event):
  41. self.SetStatusText(str(event.data))
  42.  
  43. def OnStart(self, evt):
  44.  
  45. thread.start_new_thread(self.avvia, (self,))
  46.  
  47. def OnStop(self, evt):
  48.  
  49. print 'Cliccato....'
  50.  
  51. def avvia(self, n):
  52.  
  53. for i in range(10):
  54. time.sleep(1)
  55. wx.PostEvent(n, RESULT(i))
  56.  
  57.  
  58.  
  59. class Main_App(wx.App):
  60.  
  61. def OnInit(self):
  62.  
  63. self._main_frame = Main_Frame()
  64.  
  65. self.SetTopWindow(self._main_frame)
  66.  
  67. return True
  68.  
  69. if __name__ == '__main__':
  70.  
  71. main_app = Main_App()
  72. main_app.MainLoop()

以上是关于Python-Uso diwx.PostEvent事件的主要内容,如果未能解决你的问题,请参考以下文章