1
考慮一下:的Python:如何顯示一個對話框窗口,並同時工作
import wx, time
# STEP 1: Setup Window
class Window(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Bobby the Window', size=(300,200))
panel = wx.Panel(self)
self.Bind(wx.EVT_CLOSE, self.closewindow)
wx.StaticText(panel, -1, "Yo user, the program is busy doing stuff!", (50,100), (200,100))
def closewindow(self, event):
self.Destroy()
# STEP 2: Show Window (run in background, probably with threading, if that is the best way)
if __name__=='__main__':
app = wx.PySimpleApp()
frame = Window(parent=None,id=-1)
frame.Show()
app.MainLoop()
# STEP 3: Do work
time.sleep(5)
# STEP 4: Close Window, and show user evidence of work
## *Update window to say: "I am done, heres what I got for you: ^blah blah info!^"*
exit()
我的問題是:
- 在步驟4,我該如何更改文本窗口(ESP 。如果它在一個線程中)?
- 而在步驟2中,我如何在後臺運行窗口,但仍然能夠與它通信? (更新文字等)
這與我的問題有關如何運行cli進度條並同時工作,除了gui窗口。我知道要改變StaticText,我會做'text.SetLabel(「BLAH!」)',但是如果它在後臺運行,我將如何與窗口類進行通信?
更新: This thread也是一些幫助。