用threading控制wxpython的gauge的进度。
我在网上抄了一段代码,稍微改写了一下,运行的是,进度条不能滚动,这是为什么?请各位老师指点。
import wx
import threading
import time
class GaugeFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Gauge Example', size=(350, 150))
panel = wx.Panel(self, -1)
self.count = 0
self.gauge = wx.Gauge(panel, -1, 50, (20, 50), (250, 25))
self.gauge.SetBezelFace(3)
self.gauge.SetShadowWidth(3)
self.Bind(wx.EVT_IDLE, self.OnIdle)
def OnIdle(self, event):
self.gauge.SetValue(self.count)
if self.count ==100:
self.gauge.Destroy()
def timer(self):
while self.count < 100:
self.count = self.count + 1
time.sleep(2)
if __name__ == '__main__':
app = wx.App()
frame = GaugeFrame()
frame.Show()
threading.Thread(target=frame.timer())
app.MainLoop()