wxpython 学习之 --threading

为了避免程序运行时,什么都干不了,甚至连移动窗口或者关闭的简单动作都会卡死,因此需要采用多线程。

class Mythread(threading.Thread):
  def __init__(self,window):
    super(Mythread,self).__init__()
    self.window = window
    #self.flag = threading.Event()
    #self.flag.clear() #set flag False

  def run(self):
    self.window.run()

  def stop(self):
    #os._exit(0)
    self.Close()

然后在Frame里面
def ButtonStart(self,event):
  self.job = Mythread(self)
  self.job.start() #会调用到Mythread里的run方法


如果想打开程序就执行,可以将job写在main函数里
if __name__ == '__main__':
  app = MyApp()
  frame = MyFrame(title='Log',size=(750,500))
  frame.Show()
  job=Mythread(frame)
  job.start()
  app.MainLoop()

原文地址:https://www.cnblogs.com/xia-dong/p/11718036.html