You could use pubsub which is included with wxpython -- wx.lib.pubsub
.
See my answer here for a basic example of usage for inter-thread comms.
For an alternative: An example of how you could use wx.Yield
to keep your window updated.
import wx
class GUI(wx.Frame):
def __init__(self, parent, title=""):
wx.Frame.__init__(self, parent=parent, title=title, size=(340,380))
self.SetMinSize((140,180))
self.creating_widgets = False
self.panel = wx.Panel(id=wx.ID_ANY, parent=self)
self.startButton = wx.Button(self.panel, wx.ID_ANY, 'Start')
self.stopButton = wx.Button(self.panel, wx.ID_ANY, 'Stop')
self.messageBox = wx.TextCtrl(self.panel, wx.ID_ANY, '', size=(75, 20))
self.Bind(wx.EVT_BUTTON, self.onStart, self.startButton)
self.Bind(wx.EVT_BUTTON, self.onStop, self.stopButton)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.startButton, 0, wx.ALL, 10)
self.sizer.Add(self.stopButton, 0, wx.ALL, 10)
self.sizer.Add(self.messageBox, 0, wx.ALL, 10)
self.panel.SetSizerAndFit(self.sizer)
def onStart(self, event):
self.creating_widgets = True
count = 0
self.startButton.Disable()
while self.creating_widgets:
count += 1
#Create your widgets here
#just for simulations sake...
wx.MilliSleep(100)
self.messageBox.SetLabel(str(count))
#Allow the window to update,
#You must call wx.yield() frequently to update your window
wx.Yield()
def onStop(self, message):
self.startButton.Enable()
self.creating_widgets = False
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = GUI(None)
frame.Show()
app.MainLoop()