All Pages All Books|
|
||||
|
Creating the bare minimum wxPython program
|
7
|
|||
|
|
||||
![]() |
Figure 1.3 Running hello.py on Linux
|
|||
|
Figure 1.4 Running hello.py on Mac OS X
|
||||
|
|
||||
|
1.2 Creating the bare minimum wxPython program
Let’s begin with the simplest possible wxPython program that will run successfully. Create a file named “bare.py” and type in the following code. Remember, in Python, the spacing at the start of each line is significant.
import wx
class App(wx.App):
def Onlnit(self):
frame = wx.Frame(parent=None, title='Bare') frame.Show() return True
app = App() app.MainLoop()
There’s not much to it, is there? Even at only eight lines of code (not counting blank lines) this program might seem like a waste of space, as it does little more than display an empty frame. But bear with us, as we’ll soon revise it, making it something more useful.
The real purpose of this program is to make sure you can create a Python source file, verify that wxPython is installed properly, and allow us to introduce more complex aspects of wxPython programming one step at a time. So humor us: create a file, type in the code, save the file with a name “bare.py,” run it, and make sure it works for you.
The mechanism for running the program depends on your operating system. You can usually run this program by sending it as a command line argument to
|
||||
|
|
||||
All Pages All Books