以下代码将进度条放置在状态栏的第一个字段:
self.statusbar = self.CreateStatusBar()
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([320, -1, -2])
self.progress_bar = wx.Gauge(self.statusbar, -1, style=wx.GA_HORIZONTAL|wx.GA_SMOOTH)
如何在字段号中放置进度条。2的状态栏?
状态栏有一个很好的自定义扩展,叫做EnhancedStatusBar,你可以在这里找到:http://xoomer.virgilio.it/infinity77/main/EnhancedStatusBar.html
它允许你添加几乎任何小部件到状态栏。下面是使用这个小部件向状态栏的第二个字段添加进度条的示例:
import EnhancedStatusBar
import wx
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Enhanced Statusbar Demo")
panel = MyPanel(self)
self.statusbar = EnhancedStatusBar.EnhancedStatusBar(self)
self.statusbar.SetSize((-1, 23))
self.statusbar.SetFieldsCount(2)
self.SetStatusBar(self.statusbar)
self.progress = wx.Gauge(self.statusbar, range=20)
self.statusbar.AddWidget(self.progress, pos=1)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.updateGauge)
self.timer.Start(100)
#----------------------------------------------------------------------
def updateGauge(self, event):
""""""
self.progress.Pulse()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()
在Windows 7上测试Python 2.6/wxPython 2.8和Python 2.7/wxPython 2.9。然而,它似乎不能与wxPython 3一起工作。