Cross-platform gui toolkit for deploying Python applications Cross-platform gui toolkit for deploying Python applications python python

Cross-platform gui toolkit for deploying Python applications


Please don't hesitate to expand this answer.

Tkinter

Tkinter is the toolkit that comes with python. That means you already have everything you need to write a GUI. What that also means is that if you choose to distribute your program, most likely everyone else already has what they need to run your program.

Tkinter is mature and stable, and is (at least arguably) quite easy to use.I found it easier to use than wxPython, but obviously that's somewhat subjective.

Tkinter gets a bad rap for looking ugly and out of date. While it's true that it's easy to create ugly GUIs with Tkinter, it's also pretty easy to create nice looking GUIs. Tkinter doesn't hold your hand, but it doesn't much get in the way, either. Tkinter looks best on the Mac and Windows since it uses native widgets there, but it looks OK on linux, too.

The other point about the look of Tkinter is that, for the most part, look isn't as important as people make it out to be. Most applications written with toolkits such as Tkinter, wxPython, PyQT, etc are special-purpose applications. For the types of applications these toolkits are used for, usability trumps looks. If the look of the application is important, it's easy enough to polish up a Tkinter application.

Tkinter has some features that other toolkits don't come close to matching. Variable traces, named fonts, geometry (layout) managers, and the way Tkinter processes events are still the standard to which other toolkits should be judged.

On the downside, Tkinter is a wrapper around a Tcl interpreter that runs inside python. This is mostly invisible to anyone developing with Tkinter, but it sometimes results in error messages that expose this architecture. You'll get an error complaining about a widget with a name like ".1245485.67345" which will make almost no sense to anyone unless you're also familiar with how Tcl/tk works.

Another downside is that Tkinter doesn't have as many pre-built widgets as wxPython. The hierarchical tree widget in Tkinter is a little weak, for example, and there's no built-in table widget. On the other hand, Tkinter's canvas and text widgets are extremely powerful and easy to use. For most types of applications you will write, however, you'll have everything you need. Just don't expect to replicate Microsoft Word or Photoshop with Tkinter.

I don't know what the license is for Tkinter, I assume the same as for python as a whole. Tcl/tk has a BSD-style license.

PyQt

It's build on top of Qt, a C++ framework. It's quite advanced and has some good tools like the Qt Designer to design your applications. You should be aware though, that it doesn't feel like Python 100%, but close to it. The documentation is excellent

This framework is really good. It's being actively developed by Trolltech, who is owned by Nokia. The bindings for Python are developed by Riverbank.

PyQt is available under the GPL license or a commercial one. The price of a riverbank PyQt license is about 400 euro per developer.

Qt is not only a GUI-framework but has a lot of other classes too, one can create an application by just using Qt classes. (Like SQL, networking, scripting, …)

Qt used to emulate GUI elements on every platform but now uses native styles of the platforms (although not native GUI toolkits): see the documentation for Mac OS X and the windows XP style

Packaging is as simple as running py2exe or pyInstaller. The content of my PyQt app looks like this on windows (I have used InnoSetup on top of it for proper installation):

pyticroque.exe           PyQt4.QtGui.pyd           unicodedata.pydMSVCP71.dll              PyQt4._qt.pyd             unins000.datMSVCR71.dll              python25.dll              unins000.exePyQt4.QtCore.pyd         sip.pyd                   _socket.pyd

QT comes with a widget designer and even in recent versions with an IDE to help design Qt software.

PySide

PySide is a LGPL binding to Qt. It's developed by nokia as a replacement for the GPL PyQt.

Although based on a different technology than the existing GPL-licensed PyQt bindings, PySide will initially aim to be API-compatible with them. In addition to the PyQt-compatible API, a more Pythonic API will be provided in the future.

wxPython

wxPython is a binding for Python using the wxWidgets-Framework. This framework is under the LGPL licence and is developed by the open source community.

What I'm really missing is a good tool to design the interface, they have about 3 but none of them is usable.

One thing I should mention is that I found a bug in the tab-view despite the fact that I didn't use anything advanced. (Only on Mac OS X) I think wxWidgets isn't as polished as Qt.

wxPython is really only about the GUI-classes, there isn't much else.

wxWidgets uses native GUI elements.

An advantage wxPython has over Tkinter is that wxPython has a much larger library of widgets from which to choose from.

Others

I haven't got any experience with other GUI frameworks, maybe someone else has.


I'm just weighing in to say that TKinter sucks. It sadly seems that it is packed with Python because of backwards compatibility.

The documentation is horrible. It looks horrible. I have run into some bizarre bugs that will actually crash Python.


Jython.

Jython is an implementation of the high-level, dynamic, object-oriented language Python written in 100% Pure Java, and seamlessly integrated with the Java platform. It thus allows you to run Python on any Java platform.

You can use either Swing, Applet, or other GUI frameworks available to Java platform. See Java Tutorials for Graphical User Interfaces and 2D Graphics. There are plenty of books and documentation such as API reference.

Here's a Hello world Swing application from An Introduction to Jython.

from javax.swing import *frame = JFrame("Hello Jython")label = JLabel("Hello Jython!", JLabel.CENTER)frame.add(label)frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)frame.setSize(300, 300)frame.show()

Here's a Jython applet by Todd Ditchendorf that demonstrates multi-threaded particle drawing (60 lines).

from __future__ import nested_scopesimport java.lang as langimport java.util as utilimport java.awt as awtimport javax.swing as swingclass Particle:    def __init__(self,initX,initY):    self.x = initX    self.y = initY    self.rng = util.Random()    def move(self):    self.x += self.rng.nextInt(10) - 5    self.y += self.rng.nextInt(20) - 10    def draw(self,g2):    g2.drawRect(self.x,self.y,10,10)class ParticleCanvas(awt.Canvas):    def __init__(self,newSize):    awt.Canvas.__init__(self,size=(newSize,newSize))    def paint(self,g2):    for p in self.particles:        p.draw(g2)class ParticleApplet(swing.JApplet):    def init(self):    self.canvas = ParticleCanvas(self.getWidth())    self.contentPane.add(self.canvas)    def start(self):    n = 10    particles = []    for i in range(n):        particles.append(Particle(150,150))    self.canvas.particles = particles    self.threads = []    for i in range(n):        self.threads.append(self.makeThread(particles[i]))        self.threads[i].start()    def makeThread(self,p):    class MyRunnable(lang.Runnable):        def run(this):        try:            while 1:            p.move()            self.canvas.repaint()            lang.Thread.sleep(100)        except lang.InterruptedException:            return    return lang.Thread(MyRunnable())

If you are just interested in drawing lines and circles you can probably cut it down to half.