您的位置:首页 > 编程语言 > Python开发

wxPython下Gauge进度条由线程控制

2015-06-25 23:32 1501 查看
import wx
import time
import thread

class GuageFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Gauge Example', size = (500, 200))
panel = wx.Panel(self, -1)
panel.SetBackgroundColour("white")
self.count = 0
self.gauge = wx.Gauge(panel, -1, 10, (50, 50), (300, 20), style = wx.GA_PROGRESSBAR)
self.gauge.SetBezelFace(3)
self.gauge.SetShadowWidth(3)
#进度条自身绑定循环任务,监听进度
self.gauge.Bind(wx.EVT_IDLE, self.OnIdle)
self.Center(True)

def OnIdle(self, event):
self.gauge.SetValue(self.count)
if self.count == 10:
#到达计划进度,取消进度条
self.gauge.Destroy()

def timer(self, no, interval):
while self.count<10:
time.sleep(interval)
self.count += 1

if __name__ == '__main__':
app = wx.App()
frame = GuageFrame()
frame.Show()
#创建线程,设定延迟加载时间及间隔执行时间
thread.start_new_thread(frame.timer, (0.5,0.2))
app.MainLoop()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  wxpython thread