Cross platform gui toolkit for deploying Python applications

Based on: http://www.reddit.com/r/Python/comments/7v5ra/whats_your_favorite_gui_toolkit_and_why/

Advantages:

1 - ease of design / integration - learning curve

2 - support / availability for * nix, Windows, Mac, additional points for embedded l & f, support for mobile or web sites

3 - pythonic API

4 - quality of documentation - I want to do something more complex, now what?

5 - easy packaging, so there is no need to include a full installer (py2exe, py2app will ideally work as is, and not generate a gazillion MBs file)

6 - licensing

7 - others? (Specify)




Rivals:

1 - tkinter currently supported (since 2.6, 3.0)

2 - pyttk library

3 - pyGTK

4 - pyQt

5 - wxPython

6 - HTML-CGI via Python-based framework (Django, Turbogears, web.py, Pylons ...) or Paste

7 - others? (Specify)

+45
python user-interface cross-platform
Feb 06 '09 at 11:43
source share
5 answers

Please feel free to expand this answer.

Tkinter

Tkinter is a toolkit that comes with python. This means that you already have everything you need to write a graphical interface. It also means that if you decide to distribute your program, most likely everyone else already has what it takes to run your program.

Tkinter is mature and stable and (at least possibly) pretty easy to use. It was easier for me to use it than wxPython, but obviously this is somewhat subjective.

Tkinter gets a bad rap for looking ugly and outdated. While it is true that it's easy to create ugly GUIs using Tkinter, it's also pretty easy to create nice GUIs. Tkinter does not hold your hand, but that does not bother you either. Tkinter looks best on Mac and Windows because it uses its own widgets, but it also looks fine on Linux.

Another view of Tkinter is that, for the most part, the look is not as important as people do. Most applications written using toolkits such as Tkinter, wxPython, PyQT, etc., are special applications. For the types of applications for which these tools are used, the appearance of usability looks. If the appearance of the application is important, it's easy enough to polish the Tkinter application.

There are some features in Tkinter that other tools are not suitable for matching. Trace variables, named fonts, geometry managers (layout), and the way that Tkinter processes handle events are still the standard against which other tools should be evaluated.

In the opposite direction, Tkinter is a wrapper around the Tcl interpreter that runs inside python. This is mostly invisible to those who develop Tkinter, but sometimes lead to error messages that reveal this architecture. You will receive an error message related to widgets with the name ".1245485.67345", which makes little sense if you are not familiar with how Tcl / tk works.

Another disadvantage is that Tkinter does not have as many built-in widgets as wxPython. For example, the hierarchical tree widget in Tkinter is a bit weak, and there is no built-in table widget. Tkinter canvases and text widgets, on the other hand, are extremely powerful and easy to use. For most types of applications you will write, however, you will have everything you need. Just don't expect Microsoft Word or Photoshop replication with Tkinter.

I do not know what a license is for Tkinter, I assume the same as for python in general. Tcl / tk has a BSD style license.

Pyqt

It is built on top of Qt , a C ++ framework. It is quite advanced and has some good tools like Qt Designer for developing your applications. You should know that this is not like Python 100%, but close to it. The documentation is excellent.

This structure is really good. It is actively developed by Trolltech, which is owned by Nokia. Links for Python are developed by Riverbank.

PyQt is available under the GPL or commercial. The price of a PyQt license on the river bank is about 400 euros per developer.

Qt is not only a graphical interface, but also many other classes, you can create an application simply using the Qt classes. (Like SQL, networking, scripting, ...)

Qt is used to emulate GUI elements on each platform, but now uses its own platform styles (although not built-in GUI tools): 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 application looks like this on windows (I used InnoSetup on top of it to install correctly):

 pyticroque.exe PyQt4.QtGui.pyd unicodedata.pyd
 MSVCP71.dll PyQt4._qt.pyd unins000.dat
 MSVCR71.dll python25.dll unins000.exe
 PyQt4.QtCore.pyd sip.pyd _socket.pyd

QT comes with a widget designer and even in the latest versions with the IDE to help with Qt software development.

Pyside

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

Although technology-based than 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 Python binding using wxWidgets -Framework. This scheme is licensed by LGPL and is developed by the open source community.

What I really miss is a good tool for developing an interface, they have about 3, but none of them can be used.

One thing I should mention is that I found a tab error, even though I didn't use anything advanced. (Mac OS X only) I think wxWidgets is not polished like Qt .

wxPython is really just about GUI classes, there aren't many.

wxWidgets uses its own GUI elements.

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

Other

I have no experience with other GUIs, maybe someone else has it.

+43
Feb 06 '09 at 12:06
source share

I would definitely appreciate it if someone knew something better than was usually discussed; I see that headaches are finding something suitable ...

Qt is great, but PyQt doesn't seem to have the same development resources. It seems that it has some clever way to generate bindings, but it is not complete (for example, the PyKDE kpart terminal), and there is a lack of documentation (as the developers admit). The compatibility with the Qt UI designer is good.

wxpython - the controls are not so pretty, the widget library is not as big as KDE.

OpenGL - does not even support default fonts ... pygame is fine, but opengl, which is a state machine, is too annoying (object-oriented models do not allow you to make a call in the wrong state).

XUL is a neat idea, I would like it to work. pyxulrunner the tutorial didn’t work for me - at first I had to add the path xulrunner / usr / lib to LD_LIBRARY_PATH, then it still had problems with "from xpcom import components" ...

My wishlist for the ui library will be

  • Integration with Python (for example, uses built-in functions like unicode, modules like threads and language functions like closing).
  • good intermediate view (e.g. XUL instead of generating hundreds of lines similar to "listbox91.addChild (label28)")
  • simple mutlithreaded support (automatic locks or posting events, for example, elt.setText can be called from any thread, let the developer manage the lock using Python locks, if necessary)
  • user functions, as well as a script for the sequence of user interface events, the ability to bind keys (KDE has dcop, but afaik binding is not performed automatically by the user interface library) and intercepts events.
  • potential for a large, easy-to-use standard library.
  • although if the library was well designed and received enough interest, that would be a given.

In my experience, html is much easier to get something attractive than user interface libraries.

edit - after working with PyQt 4 for some time it does work for simple user interfaces. I am not currently developing for end users, so the views don't matter. QTextBrowser is very useful for displaying basic HTML tables and creating HTML links.

+5
Mar 29 '09 at 6:03
source share

Jython

Jython is a high-level, dynamic, object-oriented Python implementation written in 100% Pure Java and integrates seamlessly with the Java platform. This allows you to run Python on any Java platform.

You can use either Swing, Applet, or other graphical interfaces available for the Java platform. See Java Tutorials for Graphical User Interfaces and 2D Graphics . There are many books and documentation , such as an API Link .

Here's the Hello Hello Swing application from 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 is the Jython Todd Dichendorff applet, which shows a multi-threaded particle pattern (60 lines).

 from __future__ import nested_scopes import java.lang as lang import java.util as util import java.awt as awt import javax.swing as swing class 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're just curious about drawing lines and circles, you can probably cut it to half.

+5
May 19 '09 at 8:55 a.m.
source share

I just weigh in to say that TKinter sucks. It is sad that it is packed with Python due to backward compatibility.

The documentation is terrible. It looks awful. I came across some strange errors that actually crash Python.

+5
May 19 '09 at 9:01 a.m.
source share

Pro wxPython

  • Many textbooks
  • wxGlade as an editor: not yet perfect, but useful.
0
Feb 06 '09 at 16:21
source share



All Articles