views:

2030

answers:

5

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

Merits:

1 - ease of design / integration - learning curve

2 - support / availability for *nix, Windows, Mac, extra points for native l&f, support for mobile or web

3 - pythonic API

4 - quality of documentation - I want to do something a bit more complicated, now what?

5 - light weight packaging so it's not necessary to include a full installer (py2exe, py2app would ideally work as-is and not generate a gazillion MBs file)

6 - licensing

7 - others? (specify)


Contenders:

1 - tkinter, as currently supported (as of 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)

+13  A: 

Please don't hesitate to expand this answer.

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.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 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.

Others

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

Georg
Qt simulates native Windows widgets, and I've yet to see one that doesn't look native enough, so for all practical purposes they *are* native
Eli Bendersky
I've changed it, but why not do it yourself, it's a community wiki after all.
Georg
"What I'm really missing is a good tool to design the interface, they have about 3 but none of them is usable." I think the best method is to code the main Frame by hand and use wxGlade for dialogs and so forth. I agree the designers could be better.
Fara
Far from nice to work with it. Plus wxWidgets won't use system-dependent margins when used with such tools.
Georg
A: 

Pro wxPython

  • Lots of tutorials
  • wxGlade as an Editor: not perfect yet, but usable.
Danny
+1  A: 

I would definitely appreciate it if anyone knows of something better than what's commonly discussed; I see to have headaches finding something appropriate...

Qt is great, but PyQt doesn't seem to have the same development resources. It seems to have some clever way to generate bindings, but isn't complete (e.g. PyKDE terminal kpart) and there is a dearth of documentation (as the developers admit). Compatibility with Qt's UI designer is nice.

wxpython - controls aren't as nice looking, widget library isn't as large as KDE.

OpenGL - doesn't even support fonts by default... pygame is okay, but opengl being a state machine is too annoying (object oriented models prevent making the a call in the wrong state).

XUL - neat idea, I wish it worked. The pyxulrunner tutorial didn't work for me, though -- first I had to add the xulrunner /usr/lib path to LD_LIBRARY_PATH, then it still had problems with "from xpcom import components"...

my wishlist for a ui library would be

  • Python integration (i.e. uses builtins like unicode, modules like threading, and language features like closures)
  • good intermediate representation (like XUL instead of generating hundreds of lines looking like "listbox91.addChild(label28)")
  • simple mutlithreaded support (automatic locks or event posting so e.g. elt.setText can be called from any thread; let the designer manage locking with Python locks if necessary)
  • user-centric features as well - scripting of a sequence of UI events, ability to keybind anything (KDE has dcop, but afaik binding isn't done automatically by the UI library), and intercept events.
  • potential for a large, easy-to-contribute standard library.
  • documentation, though if the library was well designed and generated enough interest, this would be a given.

In my experience, html is so much easier to get something good-looking up than UI libraries.

edit - after working with PyQt 4 for a while, it gets the job done for simple UI's. I'm currently not developing for end users, so looks don't matter. The QTextBrowser is very useful for displaying basic HTML tables and generating HTML links.

gatoatigrado
I don't understand your complaint about PyQt. There is only one guy working on it, yes, but the job is quite simple: map the C++ Qt DLL in python, and it's performed by an automatic tool sip. The that guy's job is just to maintain sip, which he has been doing very well for the last 9 years.Then you complain about PyKDE but this is offtopic, the question is about Qt.
Bluebird75
I know that; I'm not trying to assault him. As I said in the edit on the bottom, Qt gets the job done for me. I am simply trying to evaluate the entire gui toolkit, regardless of what the project sets out to do (or what's Qt's fault vs. PyQt's). The question involves any GUI toolkit, and many compelling features, e.g. the terminal integration, etc. are widgets that come with KDE (and PyKDE is not complete). Further, the stage of code generation is not as flexible as other options; e.g. to load a common resources.rc file not in the same directory as the GUI, one has to modify sys.path.
gatoatigrado
+1  A: 

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_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 are just interested in drawing lines and circles you can probably cut it down to half.

eed3si9n
What Java GUI lib are you suggesting ? How big is it --pages of doc, lines of code for say a canvas with draw rect / line / text ? Thanks
Denis
+2  A: 

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.

Unknown