wxpython中可以轻松地实现进度条,便于提示:
第一种是实现ProgressDialog,第二种是使用gauge.
import wx if __name__ == "__main__": app = wx.PySimpleApp() progressMax = 100 dialog = wx.ProgressDialog("A progress box", "Time remaining", progressMax, style=wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME) keepGoing = True count = 0 while keepGoing and count < progressMax: count = count + 1 wx.Sleep(1) keepGoing = dialog.Update(count) dialog.Destroy()
请看示意图:
至于gauge,可以使用下面的代码:
#!/usr/bin/env python # -*- coding: utf-8 -*- import wx 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, 100, (100, 50), (300, 30), style = wx.GA_PROGRESSBAR) self.gauge.SetBezelFace(3) self.gauge.SetShadowWidth(3) self.Bind(wx.EVT_IDLE, self.OnIdle) self.Center(True) def OnIdle(self, event): self.count = self.count + 1 if self.count >= 95: self.count = 0 self.gauge.SetValue(self.count) if __name__ == '__main__': app = wx.App() frame = GuageFrame() frame.Show() app.MainLoop()
看看图示吧
实际需要是可以根据上面的代码修改进度条.