wxPython中的Marquee风格progressbar
有谁能告诉我如何在wxPython中实现一个字幕风格的进度条吗?如以下所述: 您可以以显示的方式设置动画 活动,但不表示什么 任务完成的比例 多谢各位 我试过了,但似乎不起作用。计时器滴答作响,但仪表不滚动。有什么帮助吗wxPython中的Marquee风格progressbar,python,wxpython,Python,Wxpython,有谁能告诉我如何在wxPython中实现一个字幕风格的进度条吗?如以下所述: 您可以以显示的方式设置动画 活动,但不表示什么 任务完成的比例 多谢各位 我试过了,但似乎不起作用。计时器滴答作响,但仪表不滚动。有什么帮助吗 import wx import time class MyForm(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "Timer Tutorial 1
import wx
import time
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Timer Tutorial 1",
size=(500,500))
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.gauProgress = wx.Gauge(panel, range=1000, pos=(30, 50), size=(440, 20))
self.toggleBtn = wx.Button(panel, wx.ID_ANY, "Start")
self.toggleBtn.Bind(wx.EVT_BUTTON, self.onToggle)
def onToggle(self, event):
btnLabel = self.toggleBtn.GetLabel()
if btnLabel == "Start":
print "starting timer..."
self.timer.Start(1000)
self.toggleBtn.SetLabel("Stop")
else:
print "timer stopped!"
self.timer.Stop()
self.toggleBtn.SetLabel("Start")
def update(self, event):
print "\nupdated: ",
print time.ctime()
self.gauProgress.Pulse()
# Run the program
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
wxGauge有一个Pulse()函数
以下是一个例子:
def loadBallots(self):
self.dirtyBallots = Ballots()
self.dirtyBallots.exceptionQueue = Queue(1)
loadThread = Thread(target=self.dirtyBallots.loadUnknown, args=(self.filename,))
loadThread.start()
# Display a progress dialog
dlg = wx.ProgressDialog(\
"Loading ballots",
"Loading ballots from %s\nNumber of ballots: %d" %
(os.path.basename(self.filename), self.dirtyBallots.numBallots),
parent=self.frame, style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME
)
while loadThread.isAlive():
sleep(0.1)
dlg.Pulse("Loading ballots from %s\nNumber of ballots: %d" %
(os.path.basename(self.filename), self.dirtyBallots.numBallots))
dlg.Destroy()
if not self.dirtyBallots.exceptionQueue.empty():
raise RuntimeError(self.dirtyBallots.exceptionQueue.get())
这是我的。像这样的怎么样
class ProgressDialog(wx.Dialog):
def __init__(self, parent, title, to_add=1):
"""Defines a gauge and a timer which updates the gauge."""
wx.Dialog.__init__(self, parent, title=title, style=wx.CAPTION)
self.count = 0
self.to_add = to_add
self.timer = wx.Timer(self)
self.gauge = wx.Gauge(self, range=100, size=(180, 30))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.gauge, 0, wx.ALL, 10)
self.SetSizer(sizer)
sizer.Fit(self)
self.SetFocus()
self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
self.timer.Start(30) # or however often you want
def on_timer(self, event):
"""Increases the gauge's progress."""
self.count += self.to_add
if self.count > 100:
self.count = 0
self.gauge.SetValue(self.count)
就在我认为我已经解决了它的时候,我遇到了更多的问题。鲁迪,你能给我举个如何使用脉冲函数的例子吗。我试过谷歌和wxWiki,但都没用。谢谢。这是vista还是带有vista布局的XP?我知道XP的一个布局引擎wxGauge的脉冲显示不工作。你发布的代码在vista上有效。这在常规布局的XP上有效,但在Windows 7上无效。我猜它在WindowsVista上也不起作用。有没有办法解决这个问题?似乎这已经被报告为wxPython问题跟踪系统上的一个bug。。。这是一种方法。我以前用过这种方法。我只是觉得最好使用一些专门用来显示无限过程的进展的东西。
class ProgressDialog(wx.Dialog):
def __init__(self, parent, title, to_add=1):
"""Defines a gauge and a timer which updates the gauge."""
wx.Dialog.__init__(self, parent, title=title, style=wx.CAPTION)
self.count = 0
self.to_add = to_add
self.timer = wx.Timer(self)
self.gauge = wx.Gauge(self, range=100, size=(180, 30))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.gauge, 0, wx.ALL, 10)
self.SetSizer(sizer)
sizer.Fit(self)
self.SetFocus()
self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
self.timer.Start(30) # or however often you want
def on_timer(self, event):
"""Increases the gauge's progress."""
self.count += self.to_add
if self.count > 100:
self.count = 0
self.gauge.SetValue(self.count)