16.01.2014 Views

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

272 CHAPTER 12 ■ GRAPHICAL USER INTERFACES<br />

■Note If you’re using a package system with au<strong>to</strong>matic downloads, such as those found in Debian Linux<br />

and Gen<strong>to</strong>o Linux, for example, you may very well be able <strong>to</strong> get wx<strong>Python</strong> directly through that system.<br />

If none of the binaries fit your hardware or operating system (or <strong>Python</strong> version, for that<br />

matter), you can always download the source distribution. Getting this <strong>to</strong> compile might require<br />

downloading further source packages for various prerequisites, and is beyond the scope of this<br />

chapter. There are fairly detailed explanations on the wx<strong>Python</strong> download page, though.<br />

Once you’ve got wx<strong>Python</strong> itself, I would strongly suggest that you download the demo<br />

distribution, which contains documentation, sample programs, and one very thorough (and<br />

instructive) demo program. This demo program exercises most of the wx<strong>Python</strong> features, and<br />

lets you see the source code for each portion in a very user-friendly manner—definitely worth<br />

a look if you want <strong>to</strong> keep learning about wx<strong>Python</strong> on your own.<br />

Installation should be fairly au<strong>to</strong>matic and painless. To install Windows binaries, simply<br />

run the downloaded executables (.exe files); in OS X, the downloaded file should appear as if it<br />

were a CD-ROM that you can open, with a .pkg you can double-click; <strong>to</strong> install using RPM, consult<br />

your RPM documentation (or take a look at the brief discussion in Chapter 1). Both the Windows<br />

and OS X versions will start an install wizard, which ought <strong>to</strong> be simple <strong>to</strong> follow. Simply accept<br />

all default settings and keep clicking “Continue” and finally “Finish.”<br />

Getting Started<br />

To see whether your installation works, you could try out the wx<strong>Python</strong> demo (which must be<br />

installed separately). In Windows, It should be available in your Start menu; when installing it<br />

in OS X, you could simply drag the wx<strong>Python</strong> Demo file <strong>to</strong> Applications, and then run it from<br />

there later. Once you’ve finished playing with the demo (for now, anyway), you can get started<br />

writing your own program, which is, of course, much more fun.<br />

To get started, import the wx module:<br />

import wx<br />

There are several ways of writing wx<strong>Python</strong> programs, but one thing you can’t escape is<br />

creating an application object. The basic application class is called wx.App, and it takes care of<br />

all kinds of initialization behind the scenes. The simplest wx<strong>Python</strong> program would be something<br />

like this:<br />

import wx<br />

app = wx.App()<br />

app.MainLoop()<br />

■Note If you’re having trouble getting wx.App <strong>to</strong> work, you may want <strong>to</strong> try <strong>to</strong> replace it with wx.PySimpleApp.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!