Python DevCenter
oreilly.comSafari Books Online.Conferences.


Building GUI Applications with PythonCard and PyCrust

by Patrick O'Brien

Developing the Graphical User Interface (GUI) for a Python application is often a tedious, time-consuming, and opaque process. This is the exact opposite of how Python programmers would describe most other aspects of software development using Python. So what is it about GUI applications that causes them to be so hard? Perhaps more importantly, can anything be done to improve the situation? This article attempts to answer that question and describe how the PythonCard project is addressing these issues.

PythonCard is a cross-platform application framework for the wxPython GUI toolkit (which is a Python version of wxWindows). The goal of the PythonCard project is to bring the power, simplicity, and expressiveness of Python into the realm of GUI development. The project is currently in the prototype stage, but plenty of applications are being developed with it even in this early form. At this point, however, things are in a state of flux as we explore various approaches and develop tools to make GUI application development easier, faster, and more "Pythonic."

Let's start with some of the challenges programmers face during GUI development, such as widget creation, component layout, event handling, and runtime interactions. As we do so, we'll focus on characteristics of the wxPython toolkit. But it's worth noting that while all GUI toolkits are different and no characterization will apply equally to each of them, several of our observations will hold true for just about any GUI toolkit. The real issue for this article is how the PythonCard project is addressing these issues and whether you see a benefit for the kinds of applications you develop. It's also worth noting that we don't consider wxPython to be flawed. In fact, we choose to build on wxPython because we think it is the strongest cross-platform GUI toolkit available for Python. Our intent is simply to make wxPython even better and more accessible to novice GUI programmers, without closing off the ability to write straight wxPython code as a fallback when you need access to features or capabilities PythonCard may not have yet encapsulated.

As we explore these issues, we'll show the source code for a simple application, called Counter. To highlight certain differences, we're going to show the code as it would appear in wxPython and as it appears in PythonCard. Creation of the Counter application is described in Dan Shafer's excellent PythonCard tutorial. The resulting application has buttons and menu choices that increment, decrement, and reset a numeric value displayed in a text control and looks like the following figure:

Pages: 1, 2, 3, 4

Next Pagearrow

Sponsored by: