Last Updated: Thursday 12th December 2013

Python is well suited for rapid development of cross-platform applications of all sorts, and that includes desktop GUI apps. There are choices to be made when starting to develop a GUI application in Python, however, and this article provides the information you need to set out on the right path. We will discuss what serious GUI toolkits are available for Python, their strengths and weaknesses, and provide a simple demo application for each one.

Demo "hello world" application overview

The demo application is simple: a window containing a combo box that presents the choices "hello", "goodbye", and "heyo"; a text box in which free text can be entered; and a button which, when clicked, prints a greeting assembled from the values of the combo box and text box — e.g. "Hello, world!" — to the console. Here is a mockup of the example app:

Mock hello world application for GUI development

Note that all the toolkits discussed here lend themselves to a similar object-oriented approach to our simple application; it is an object that inherits from a top-level GUI object, such as an application, window, or frame. The application window is filled with a vertical layout widget which manages the arrangement of the control widgets. Other GUI toolkits for Python, such as the long-obsolete pyFLTK or the simplistic easygui, take different approaches, but the toolkits discussed here represent the mainstream of Python GUI library development.

I have attempted to provide idiomatic code for each toolkit, but I am not expert in a couple of them; please let me know in the comments if I've done anything that might be misleading to new developers, and I'll do my best to update the examples.

Choosing a Python GUI Toolkit

There are several toolkits available for GUI programming in Python; several are good, none are perfect, and they are not equivalent; there are situations where one or more otherwise excellent toolkits will not be appropriate. But the choice is not difficult, and for many applications, any GUI toolkit you choose will work. In the toolkit sections below, I've tried to honestly lay out the drawbacks and advantages of each, to help you make an informed choice.

A caution: Much of the information available online — for example, in the Python wiki's GUI article or the Python 2.7 FAQ — is out-of-date and misleading. Many of the toolkits on those pages have been unmaintained for five years or more, and others are too immature or undocumented for serious use. Also, do not use the Choose Your GUI Toolkit page I've seen bandied about here and there; its weighting code makes it almost impossible to choose anything but wxPython.

We will look at the four most popular Python GUI toolkits: TkInter, wxPython, pyGTK/PyGobject, and PyQt/PySide.

TkInter

TkInter is the grand old man of the Python GUI world, having been distributed with Python almost since the language was founded. It is cross-platform and omnipresent, stable and reliable, and easy to learn, it has an object-oriented, brilliantly Pythonic API, and it works with all Python versions, but it has some drawbacks as well:

Limited support for theming

Before Python 2.7/3.1, TkInter had no support for theming, so on every platform its custom-drawn widgets looked like Motif circa 1985. Since, the ttk module has introduced themed widgets, which improve the look somewhat but leave some unorthodox controls, such as OptionMenus, in place.

Small selection of widgets

Tkinter lacks some widgets other toolkits provide, such as non-textual listboxes, real combo-boxes, scrolled windows, and others. Some additional controls have been supplied by third parties, e.g. Tix to supply the lack. Mock up your application in advance if you consider using TkInter, and make sure it can provide every control you need, or you could get burned later.

Demo App/Hello World in Tkinter

wxPython

Note that at the time of writing, wxPython is only available for Python 2.x

Guido van Rossum, the creator of Python, says of wxPython:

wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first.

At least, he said that once, a long time ago; and how much GUI programming does Guido van Rossum do, anyway?

At any rate, wxPython does have a lot of good points. It has a vast set of widgets, native look-and-feel on Windows, Linux, and OS X, and a large-enough user base that at least the obvious bugs have been caught. It's not included with Python, but installation is easy, and it's available for all recent Python 2.x releases; wxPython is probably now the most popular GUI library for Python.

It's not perfect, though; its documentation is atrocious, and though the exemplary demo app is priceless documentation itself, it's about all the help you're going to get. I personally find the API unPythonic and unpleasant, but others disagree. Still, you'll almost never get in the middle of a project using wxPython and find it can't do what you need, which is a big recommendation for it.

Demo App/Hello World in wxPython





pyGTK/pyGobject

pyGTK is a cross-platform widget toolkit based on GTK+, a broadly-used GUI toolkit developed originally for the image manipulation program GIMP. pyGobject is a new revision of pyGTK that uses GObject introspection and supports features of GTK3. Both versions' APIs are closely related, and their capabilities and drawbacks are similar, so they can be considered as one for our purposes. The developers of pyGTK recommend using pyGobject for new development.

pyGTK only uses native widgets on Windows and Linux. Support for native widgets and windowing on OS X, though available in GTK+, is still under development in pyGTK; right now its look and feel on Mac emulates that of Linux. The widgets are, however, themeable, and there are a large number of very attractive themes. pyGTK is also most successful with Python 2.x; new versions begin to support Python 3 but are not complete, especially on Windows. Installation for Windows previously required downloading multiple packages from different sources, but recently all-in-one binary installers have been made available.

On the positive side, pyGTK is stable and well-tested and has a full selection of widgets. It also has excellent documentation and, if you like that sort of thing, an excellent visual GUI generator called Glade. Its API is straightforward and mostly simple, with only a few exceptions, and there is fairly good example code available. The bottom line for pyGTK: it is a solid and capable GUI toolkit that suffers from cross-platform inconsistency and the effects of being less popular than other equally good alternatives.

A special note about choosing pyGTK: if your application involves a variety of simple, text-based listboxes, pyGTK's design will cause problems. Its strict separation of concerns and model-view-controller division make listboxes unusually complicated to develop compared to other toolkits. Failing to observe this point put me way behind on an important project when I was new to Python GUI development.

Demo App/Hello World in pyGTK/pyGobject

PyQt/PySide

Qt is more than a widget toolkit; it is a cross-platform application framework. PyQt, its Python interface, has been around for years, and is stable and mature; it has gained some cruft over the years, with two APIs available, known as API 1 and API 2, and a large number of deprecated features. Furthermore, even though Qt is available under the LGPL, PyQt is licensed under the GNU GPL versions 2 and 3 or in a fairly expensive commercial version, limiting your licensing options for your code.

PySide is a response to the drawbacks of PyQt. It is released under the LGPL and omits all deprecated features prior to PyQt 4.5 as well as the entire API 1, but otherwise is almost fully compatible with PyQt API 2. It is slightly less mature than PyQt, but is more actively developed.

No matter which wrapper you choose, Python and Qt work beautifully together. The more modern API 2 is fairly Pythonic and is clear, there is very good documentation available (although its roots in the C++ Qt documents are obvious), and the resulting applications look smashing in recent versions, if not quite native. There is every GUI widget you could possibly desire, and Qt supplies more — interesting classes to deal with XML, multimedia, database integration, and networking — though you're probably better off using the equivalent Python libraries for most of the extra functionality.

The biggest downside of using a Qt wrapper is that the underlying Qt framework is huge. If it's important to you that your distributable package be small, choose TkInter, which is not only small, but already a part of Python. Also, while Qt employs operating system APIs to adapt its widgets to your environment, not all are strictly native; wxPython would be a better choice if native look-and-feel is a major consideration for you. But PyQt has a lot going for it, and is certainly worth consideration.

Demo App/Hello World in PyQt/PySide

Note: For Qt, I've used PySide; the example code would run using PyQt with only a few lines' difference.

  • wheaton

    Current, balanced, informative, and well written. Found the code examples to be most useful. Thanks

    • Jackson Cooper

      Thanks for the feedback Wheaton! Good to hear :).

  • Brett

    In searching for articles about python frameworks written in the last year, I’m very glad to have found this! I wish some of the older comparisons would link to this.

    • http://jacksonc.com Jackson Cooper

      Great to hear Brett, thanks!

  • dirty harry

    Hi, I’ve learned Python over the last 6 months (I’m an experienced old scholl programmer, with C and Assembler experience).. I installed PySide, but havent found a tutorial that explains how to create GUI’s clearly.. any chance you could;
    1) recommend a beginner’s tutorial in GUI with PySide
    2) Recommend a GUI designer that works with PySide, I did try one but had very unpredicctable results with it
    Thankyou kindly

    • http://jacksonc.com Jackson Cooper

      Great to hear, welcome to the dark side ;-).

      1. There’s not too many out there unfortunately. We’ve got one here, but the writer’s been too busy to keep writing, so I’m in the process of looking for someone to pick up where he left off: http://www.pythoncentral.io/series/python-pyside-pyqt-tutorial/. Note that PySide is a fork of PyQt, and they’re *almost* the same. So you may also want to look for PyQt tutorials, since it’s been around a lot longer and there’s likely a lot more tutorials on it. I’d check out this page to get started with PySide / PyQt in general: http://qt-project.org/wiki/PySideDocumentation.

      2. By far the best GUI designer (and only one that I know of) for PySide / PyQt is Qt Designer. Qt Creator (an IDE) builds this in, so it’s the same. It creates an XML file, which compiles to Python code. It’s basically just as quick as manually building a GUI, and works great. But I’d recommend that when you’re comfortable with the framework, teach yourself to build GUIs manually using containers and individual widgets with raw code. In practice I’d personally always recommend using the designer since it’s a lot quicker and no noticeable performance differences. However it’ll teach you how a lot of PySide’s internals work, and let you debug quirky problems a lot quicker.

      • Paul

        Hey Jackson, I’m also on the same (poorly documented) path and wanted to ask something: It seems the latest version of PyQT is version 5, while PySide is based on version 4.8 of PyQT. Do you know if there is a substantial difference between the two base PyQT versions and why (if at all) one would prefer version 5 over 4?

        • http://jacksonc.com Jackson Cooper

          Hey Paul. Qt 5.0 introduced several new features. You can see the difference between PyQt 4.x and PyQt 5.x here. It really depends on whether you need the features of Qt 5.0. However keep in mind that PyQt and PySide are not exactly the same, there are a few technical differences.

          Also note that PyQt is licensed under the GPL, whereas PySide is licensed under the LGPL. So if you’re developing a proprietary application, you’ll need to purchase a license from Riverbank (the producer of PyQt).

          PySide (IMHO) has a more liberal license, and has strong community support behind it. Whereas while PyQt is well developed and supported, it is at the mercy of the company behind it. AFAIK PySide doesn’t support Qt 5.0 at the moment, and it’s not even in the immediate roadmap. So several factors come into play.

  • Carl Stenquist

    Hi there needs to be a simple document how to get started with a PyQt (or PySide) project using *QtCreator*, or else its too much of a hurdle to teach oneself I think, and just use what one used before (e.g. QtCreator with C++).

    • http://jacksonc.com Jackson Cooper

      We’re in the process of pushing out some more content. I’ll make sure we’ve got some Qt Creator content in there too ;-).

  • Ted Burke

    Thanks Jason, I found this comparison incredibly useful. I’m tempted to stick with Tkinter for now.

  • Nick Danger

    I am in the process of setting up to build a GUI quickly which 1) runs on Windows 2) displays image files (start with jpg, extend to others) 3) allows me to detect cursor based interactions with the image. Is one of these tools better for this somewhat vaguely defined project?