Reputation: 6548
Consider this:
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()
My questions are:
This is similar to my question about how to run a cli progress bar and work at the same time, except with gui windows.
I know that to change StaticText, I would do 'text.SetLabel("BLAH!")', but how would I communicate that with the window class if it is running in the background?
Update: This thread was also some help.
Upvotes: 1
Views: 354
Reputation: 33071
If you need to execute a long running process, then you will have to use some type of threading or perhaps the multiprocessing module. Otherwise you will block the GUI's main loop and make it unresponsive. You will also need to use wxPython's threadsafe methods to communicate with the GUI from the thread. They are wx.CallAfter, wx.CallLater and wx.PostEvent.
You can read more about wxPython and threads at the following:
Upvotes: 1