Search code examples
python-2.7dialogwxpythonwxwidgets

Text does not display when Show() is used, but does when ShowModal() is used. (wxPython)


I am analyzing an image and it takes a little while to process. I want to have a Dialog box pop up when a user clicks the 'Analyze' button. I need it to be modeless so it does not interrupt the flow of my application (so the analyzing actually occurs). I just want it to display "Analyzing image..." until the analysis is done, at which point it goes away (meaning I don't want any buttons). Here is what I have so far:

class MessageDialog(wx.Dialog):
    def __init__(self, message, title):
    wx.Dialog.__init__(self, None, -1, title,size=(300, 120))
    self.CenterOnScreen(wx.BOTH)

    text = wx.StaticText(self, -1, message)

    box = wx.BoxSizer(wx.VERTICAL)
    box.Add(text, 1, wx.ALIGN_CENTER, 10)
    self.SetSizer(box)

I call it from my main application frame using:

msg_dialog = MessageDialog("Analyzing image...", "Analyzing")
msg_dialog.Show()
# Do some stuff.....
msg_dialog.Destroy()

When I use msg_dialog.Show() the "Analyzing image..." text does not show up. If I change it to msg_dialog.ShowModal(), the text shows up. I can't use ShowModal() though because it pauses my program, defeating the purpose of the box. Any ideas about what's going on? Thanks for the help.


Solution

  • You need to call wxWindow::Update() to force the update of the controls on the screen without returning to the event loop.

    You could also just use wxBusyInfo.