I'm new to wxPython (wxPython 3.0.0.0, python 2.7, Mac OS X), and I'm trying to display a message dialog in the OnInit function of the app. Example scripts I run work just fine using a very similar three-line code block, but when I do it with this one, the message dialog appears for a split second, and disappears. Is there something silly that I'm doing wrong?
import wx
class MyApp(wx.App):
def __init__(self):
wx.App.__init__(self, redirect=False)
def OnInit(self):
self.rootView = wx.Frame(parent=None, id=-1, title="Wire Frame",
pos=(150, 150), size=(350, 250))
self.rootView.Show()
self.SetTopWindow(self.rootView)
dlg = wx.MessageDialog(self.rootView, "Hi", "title", wx.OK|wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
return True
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
Edit: Tested this on Ubuntu with wxPython 2.8.12.1, and the behavior is normal there. I'll try and get a newer version on there to test it with. Perhaps this is a bug in wxPython? I've submitted a bug report, so I'll find out soon enough.
What will happen if you treat MessageDialog as if it is say FileDialog or similar?
import wx
class MyApp(wx.App):
def __init__(self):
wx.App.__init__(self, redirect=False)
def OnInit(self):
self.rootView = wx.Frame(parent=None, id=-1, title="Wire Frame",
pos=(150, 150), size=(350, 250))
self.rootView.Show()
self.SetTopWindow(self.rootView)
dlg = wx.MessageDialog(self.rootView, "Hi", "title", wx.OK|wx.ICON_ERROR)
#dlg.ShowModal()
if dlg.ShowModal() != wx.ID_OK:
dlg.Destroy()
return True
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
probably just a hackish way to go around but this may work...
At least, this seems to work in the same way in wxpyhon2.8 on Windows.