0

Before I made some changes to the following program, everything went fine:

Program before modification:

#! /usr/bin/env python """ A bare-minimum wxPython program """ import wx class MyApp(wx.App): def OnInit(self): return True class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title) if __name__ == '__main__': app = wx.App() frame = MyFrame(None, "Sample") frame.Show(True) app.MainLoop() 

But after I put frame into the definition of OnInit, the program runs without syntax error but nothing displayed.:(

Program after modification:

#! /usr/bin/env python """ A bare-minimum wxPython program """ import wx class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(None, "Sample") ## add two lines here self.frame.Show(True) return True class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title) if __name__ == '__main__': app = wx.App() app.MainLoop() 

I try to use the debugger and step over the program. It seems that self.frame is not defined (not even appear from beginning to end).

What am I going wrong with the program? I'm very new to Python and wxPython, please help. Thx.

EDIT:

app = MyApp() 

stdout/stderr:
NameError: global name 'Show' is not defined

1 Answer 1

1

You should create MyApp (not wx.App) object:

#! /usr/bin/env python """ A bare-minimum wxPython program """ import wx class MyApp(wx.App): def OnInit(self): self.frame = MyFrame(None, "Sample") ## add two lines here self.frame.Show(True) return True class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title) if __name__ == '__main__': app = MyApp() # <--- app.MainLoop() 
Sign up to request clarification or add additional context in comments.

1 Comment

sorry, but things become even worse. I got a NameError: global name 'Show' is not defined.