[wxpython-users] Re: [newbie] Connection between app and frame?
Christopher Barker
Chris.Barker at noaa.gov
Thu Apr 3 10:12:16 PDT 2008
Gilles wrote:
> But since I can call the frame class and instance whatever I like, how
> does app knows about frame?
As you've seen from the messages here, there are lots of ways, but my
earlier suggestion:
"put a reference to the frame in the app"
I think is the best way to go -- it's clear an concise.
The demo code form the book you're looking at is simplified to the
easiest way to get an app up. For a more complicated app, you're likely
to want to subclass wx.app. This is how you do that:
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, -1)
self.SetTopWindow(self.frame)
self.frame.Show()
return True
A = MyApp()
A.MainLoop()
Note that you do it in OnInit(), rather than __init__, 'cause the app
needs to be initialized before you can create frames and such. OnInit()
will be called after the app is initialized.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list