Python GUI programming platforms for Windows

[Edit]
By popular demand, I've added a section on PyGTK. See bottom of post.

There are several platforms for programming Windows GUI applications in Python. Below I outline a few of them, with a simple "hello world" example for each. Where I've lifted the example from another site, there's a link to the source.

Contents

Tkinter

Tkinter is the ubiquitous GUI toolkit for Python. It's cross platform and easy to use, but it looks non-native on just about every platform. There are various add-ons and improvements you can find to improve the look and feel, but the basic problem is that the toolkit implements its own widgets, rather than using the native ones provided on the platform.

Pros

Most portable GUI toolkit for Python

Very easy to use, with pythonic API

Cons

wxPython

wxPython is probably the most popular GUI toolkit for Python. It's a wrapper for the wxWidgets C++ toolkit, and as such it betrays a few unpythonic edges (like lumpy case, getters and setters, and funky C++ errors creeping up occasionally). There are a few pythonification efforts on top of wxPython, such as dabo and (the now apparently moribund) wax.

.NET with IronPython

IronPython is a .NET implementation of Python. As of 1.0 it has full support for Python 2.4 features, and the 2.0 version will duplicate the Python 2.5 feature set. Although there are many CPython libraries/modules that won't run under IronPython (namely, the ones relying on compiled extensions that have not yet been ported), this lack is partially made up by the huge .NET library.

One cool thing about IronPython is that you can easily create lightweight .exe files that you can ship off to your friends — although you pay for this with a dependency on the .NET runtime, which you can't count on random Windows users to have installed.

Of course, when you go the IronPython route, you take all that comes with it: the good things, like access to .NET libraries and possibly the easiest/cleanest optimization path of any Python implementation (C#); and the bad things, like dependence on the .NET runtime and danger of getting caught on the MS upgrade treadmill.

Another way of getting at the .NET libraries is Python.NET, which adds two files to your Python directory to enable you to call the CLR from CPython.

PyQT

PyQT is probably the third most widely used GUI toolkit, after wxPython and Tkinter. It has a dual commercial/GPL license (Edit: but it does let you use other open-source licenses; see comments below). I have to admit that this made it a non-starter for me: I don't want to pay for my toolkit when there are others just as good or better that are free; and when I do release open-source software, I want to choose my own license. For others, the GPL might be a non-issue or a plus, so I've left it off my pro/con list.

[Edit] PyQT will be available under the LGPL as of March 2009. Fantastic news.

Pyglet

Pyglet is kind of the new kid on the block in terms of GUI toolkits, but it sure made a splash. It implements its own windowing system, but with no dependencies other than Python (for Python 2.5 users). You will need OpenGL to do decent 3D graphics, but that's hardly a black mark for pyglet — other libraries would love to make it this easy.

Pros

High degree of freedom for GUI creation

Only depends on Python

Large number of widgets

Cons

Purposely doesn't duplicate the native platform look and feel

Although there are a lot of widgets, you'll have to roll your own for many things the platform gives you for free.

Win32 with ctypes

Of course, all you really need to write GUI applications on Windows with Python is your trusty ctypes module and a well worn copy of Petzold. The benefit of this style is that you're working right down at the system API level, with nothing to get in your way. The disadvantage is that you're working right down at the system API level, with nothing to relieve you from all that boilerplate (unless you write your own abstraction layer on top; see Venster, below…).

Pros

Enables high level of control

Straightforward if familiar with Win32 API

No added complexity or buried functionality due to need to be cross-platform

Venster

Venster was a very promising wrapper over the Win32 API, borrowing heavily from WTL and ATL windowing techniques. Unfortunately, the project hasn't been updated in several years, and doesn't support the latest versions of Python (especially after ctypes.com was dropped).

PyGTK

PyGTK seems to have a lot going for it as a cross-platform toolkit. It's also licensed under the LGPL, which I like a lot more than the GPL of PyQT. Unfortunately, it doesn't use native Windows widgets; it does a pretty good job of faking it, but it stands out like a Win32, .NET, or wxPython app wouldn't.

Pros

Cross platform

Lots of widgets

Voluminous (if somewhat disorganized) documenation

Cons

Native Win32 widgets not used (looks good, but not quite all the way there)

57 comments to Python GUI programming platforms for Windows

I was just scrolling through the introduction of wxPython in Action by Manning Publications.

Here is what it says on page 19

Why choose wxPython?
The most powerful benefit of wxPython depends on your needs and expertise.
While we think that all user interface (UI) programmers would benefit from using
wxPython, the specific features that are most helpful will vary from case to case.

1.6.1 Python programmers
If you are already a Python programmer, you’ve probably noticed that Tkinter,
the interface toolkit distributed with Python, has some problems:

■ Tkinter is based on the Tk toolkit, which is somewhat out-of-date in terms
of the kinds of widgets it supports. By default, it doesn’t support more com-
plex widgets such as tree controls or tabbed windows. It also doesn’t have a
particularly rich set of predefined dialogs.

■ The Tk toolkit does not use native widget support, resulting in an applica-
tion that looks foreign on all platforms. In wxPython, dialogs and widgets
will look like those that are standard on the underlying operating system.
Your Tk user will find that buttons, fonts, and menus all look slightly differ-
ent from what might be expected.

■ Many programmers find Tkinter itself somewhat clunky to work with. In
particular, the process by which events are translated to actions in wxPy-
thon is more flexible and powerful.

You’ll find that wxPython solves these problems. The toolkit in wxPython is vastly
more complete and extensive than that of Tkinter and the native widget support
means your application will look at home in your operating system. Additionally,
the Python language support is more fluid in wxPython, making for a somewhat
nicer programming experience.

@pyglet hello world, I used the tutorial, great btw thx. I found the the window wont close properly unless after the while not loop win.close() follows. This is at least my case just thought you might like to know 😛