always found that the best way to learn is by doing and then
experimenting and tweaking with what’s been done. So download
wxPython, fire up your favorite text
editor and get ready to
play along as you read the next few sections.
A simple example
Familiarize yourself with this little
program, and refer back to it as you read through the explanations
from wxPython.wx import * class MyApp(wxApp): def OnInit(self): frame = wxFrame(NULL, -1, "Hello from wxPython") frame.Show(true) self.SetTopWindow(frame) return true app = MyApp(0) app.MainLoop()
When you run this code, you should see a Window appear similar to Figure 20.6.
The first thing to do is import the entire
wxPython library with the
* statement. This is common practice for
wxPython programs, but you can obviously perform
more restrictive imports if you prefer.
wxPython application needs to derive a class
wxApp and provide an
OnInit method for it. The framework calls this
method as part of its initialization sequence, and the usual purpose
OnInit is to create the windows and essentials
necessary for the program to begin operation. In the sample you
created a frame with no parent, with a title of “Hello from
wxPython" and then showed it. We could also have specified a position and size for the frame ...