我發現wx.CallAfter
和wx.CallLater
在文檔中,但都沒有解決我的問題。 我想要做的是在做任務時更新狀態欄,但wx.CallAfter
和wx.CallLater
只在任務後更新。在wxpython中有一個wx.CallDuring
例子:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by wxGlade 0.6.3 on Fri Sep 30 20:55:34 2011
import wx
import time
# begin wxGlade: extracode
# end wxGlade
class MyFrame1(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame1.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.frame_2_statusbar = self.CreateStatusBar(1, 0)
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame1.__set_properties
self.SetTitle("frame_2")
self.frame_2_statusbar.SetStatusWidths([-1])
# statusbar fields
frame_2_statusbar_fields = ["foo"]
for i in range(len(frame_2_statusbar_fields)):
self.frame_2_statusbar.SetStatusText(frame_2_statusbar_fields[i], i)
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame1.__do_layout
self.Layout()
# end wxGlade
def Test(self):
time.sleep(10)
for i in range(0,100):
time.sleep(0.1)
txt="I <3 Stack Exchange x " +str(i)
wx.CallAfter(self.frame_2_statusbar.SetStatusText,txt, 0)
wx.CallAfter(self.Update)
print txt
# end of class MyFrame1
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame1(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
wx.CallAfter(frame_1.Test)
app.MainLoop()
wx.Yield(),作品謝謝:) – linuxrules94