Cross-platform gui toolkit for deploying Python applications - python

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)

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

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.

Pro wxPython
Lots of tutorials
wxGlade as an Editor: not perfect yet, but usable.

Related

Looking for (wxPython) Python 2D drawing framework

I'm looking for a framework for drawing 2D scenes in Python. Not for game programming, but for 'office' like applications (e.g. drawing diagrams, mindmaps etc).
Preferable something that can be used with wxPython.
wxPython comes with OGL, but that is very old and no-one seems to use it any more (I couldn't find a reference to it in any recent project in sourceforge or google code).
The Qt (PyQt) framework has the Scenegraph thing, which I've used in some C++ projects, but I think PyQt with the Qt dependencies is too big.
Requirements are :
- managing objects
- hit-testing of objects
- ability to print the scenes
- modern look (at least anti-aliasing of lines)
I've been looking for some days now, but can't find anything that even comes close to PyQt's Scenegraph. I've been thinking about modifying OGL to use a wxGraphicsContext...
P.S. Anyone using OGL, please shout 'OGL is not dead' :-)
You might be able to use floatcanvas for this. Joran mentioned PyGame, which is certainly a legitimate option. I would also take a look at the WhyteBoard project (https://code.google.com/p/whyteboard/) which is written in wxPython and does a few of the items you mentioned. Finally, wxPython supports Cairo, which you also might find helpful. There are several demos of Cairo in the wxPython demo. By the way, wx.GraphicsContext (which you had mentioned) supports anti-aliasing, as does Cairo.

Framework for paint program

I've decided to start working on a personal project, attempting to develop a cross platform, MSPaint like app. Oddly enough, I find mspaint is one of the applications I miss the most on Linux or OS X, so I want to try to make something similar. Tuxpaint, mtpaint, gpaint, etc. are all old and inactive and ugly. I don't want to make GIMP, just the basics, similar in features to MS Paint.
I'm thinking of doing it in python with the pygtk toolkit, but I was interested to hear your suggestions. Would C/C++ be a better choice, or even C# (gasp!) with mono? How about using Qt as opposed to GTK, or maybe some other fancy library I don't know about (Please, not FLTK!). I'd be curious to hear your thoughts.
Thanks!
Qt's canvas object (or its newer replacement QGraphicsView) can do pretty cool things. Whether you choose C++ or python is a matter of personal choice, as Qt is supported in both languages. For a simple project like this I'd choose python because killer performance is not much of an issue, and it will be much easier to write.
Another thing to look into is making this app web based with HTML5's canvas object and Javascript. It can be surprisingly robust, and anything that can be put on the cloud is a win in most cases.
If you decide to go with Python (which would be my choice because it's such a simple language), then TkInter is considered the de-facto standard GUI package. That link should send you to some excellent starting references for TkInter, although I also really like Not_a_Golfer's suggestion of an HTML5 web-app.
Short: You can use both, no third party library is guaranteed to be distributed with all major distributions.
Long:
Gtk+ vs. Qt
What do you want incorporate into your application. If it is just selecting a brush, selecting color you could pretty much use any gui toolkit.
If you are going to run it as a web-based tool, Gtk+ has an html5 backend renderer (I don't know about Qt)
A sidenote:
I recommend to use the toolkit's native programming language (gtk+ C, Qt C++) - if you don't, you will suffer from delays with bugfixes, generally more bugs and delayed releases, though for that case it shouldn't really matter.
Everything else boils down to personal preferences and there already exist some questions to tackling that issue.
if you are using qt,you can use QtitanRibbon

High(er) level frameworks that wrap Tkinter/ttk

Curious if there are any higher level frameworks that attempt to wrap Tkinter? For example, wxPython is wrapped by the Dabo framework (http://dabodev.com/) and PythonCard.
Motivation: We've recently moved to Python 2.7 (Windows) and are very impressed with the new ttk (Tile) support which allows one to build professional quality, platform native GUI's using the built-in Tkinter framework. In the past we would have used wxPython to create simple GUI interfaces for our command line utilities, but we're re-thinking this strategy in favor of using Tkinter/ttk for these use cases.
We're new to Tkinter (coming from wxPython) and while Tkinter/ttk seem to be simple to use, there seems to be a lot of repeated boilerplate code that we're writing. Before we try to wrap up some of our code in a home made set of classes, I want to make sure that we're not re-inventing the wheel.
Probably a little bit late for you. But I've just released a tkinter framework in beta called tKroopy. Which aims to provide a means for switching between dialogs and provide some higher level widgets, like easily displaying tabulated data.
It was designed for building lots of small to medium applications and grouping them together in a single application, but there is no reason why you couldn't use it to build a single large scale application too.
https://github.com/tKroopy/tkroopy
The only one I knew about seems quite stale, Python megawidgets.
You can find a list of others on the Tkinter wiki.
tkRAD supports python 2 and 3 and looks mature
https://pypi.python.org/pypi/tkRAD/1.6.5

Which GUI framework to learn when you know scripting and HCI

I have some knowledge about Human computer interaction and some basic knowledge programming scripts (Python) that run from start to finish and automate some tasks I want to do or calculations. In the past I built interfaces in HTML with PHP behind it.
I would like my python scripts to evolve from the command line and build some applications with GUIs that would allow the user to drag files and push buttons to initiate operations and check progress graphically.
Since I write my scripts in Python I looked at some of the options (Tkinter, wxPython, PyQt) but I can't make a decision between them to invest my time learn one and not the other. My criteria:
Has a introduction for programmers for GUI (what are the differences from a script, examples of some simple interfaces)
A framework that would allow me to run my programs on the platforms I use most (Windows) but that can also run on Mac and maybe Linux, without too much modification.
Very shallow learning curve (easy to make first interfaces) but flexibility later on to customize the interface beyond what the typical OS allows (different colors, size and shapes of buttons, for example)
If not the same, similar to how you program GUI for Android and/or Nokia smartphones. I'm planning to write some programs for these platforms in the near future so I would like to carry over some of the lessons here onto those platforms, if possible.
I did find this previous question but none of the answers are satisfactory.
Does any of the frameworks fit these requirements better than the others or are they essentially similar and I would be happy with any of them?
Note: If you think I should consider other language rather than Python to achieve this, which one? I really like Python whitespace syntax and have grown used to it so I would prefer to stick with it.
PyQt and/or the very similar Nokia-sponsored PySide (with a more "relaxed" license, LGPL instead of GPL, and the same underlying toolkit, Qt) do offer the advantage of similarity with Nokia's smartphones GUI toolkit (your fourth point) -- Nokia purchased Trolltech, the makers of Qt, exactly because Qt was the fundamental GUI toolkit for their mobile offerings.
All the toolkits you mention satisfy the conditions you pose about operating systems (Windows, Mac, Linux), your second point.
Your first and to some extend third points depend in good part of what learning materials you have available for each of the toolkits. To my tastes, it seems that wxPython's tutorial (the new one in wiki form is what I'm pointing to and recommending) is really good, and PyQt's not bad at all; PySide's docs don't include a good tutorial (that I know of), I believe PySide's intention is that you first learn PyQt (with the reasonable available materials), then apply these few differences to be programming in PySide instead of PyQt;-). Tkinter's tutorials that I can find are either very old or focused on the underlying toolkit's multi-language nature, which I think makes them inferior.
If you can afford a book, PyQt has a good one (also applies to PySide, as above) -- this excellent and free one is unfortunately very old, so I don't think it helps. wxPython's own book is also quite good; tkinter's, again, is very dated.
Personally I recommend PyQt / PySide: overall power A+, ease to get started (with the above tutorial and book) A-, Nokia-phone programmer similarity A. For wxPython I'd say power A, ease A, Nokia-similarity B. Tkinter's dated tutorials and book are important negatives.
You also mention Android, but I don't see how anything could be similar to both Android and Nokia's phone-GUI programming at the same time. Maybe I'm not familiar enough with Android GUI programming, but it seems to me that it differs from every one of the toolkits you've mentioned.
PyGTK fufills at least the first three points. I'm not sure on the fourth. It has a nice tutorial here: http://www.pygtk.org/pygtk2tutorial/index.html
I guess you are looking for Glade.
The site says:
Glade is a RAD tool to enable quick & easy development of user
interfaces for the GTK+ toolkit and the GNOME desktop environment.
The user interfaces designed in Glade are saved as XML, and by using
the GtkBuilder GTK+ object these can be loaded by applications
dynamically as needed.
By using GtkBuilder, Glade XML files can be used in numerous
programming languages including C, C++, C#, Vala, Java, Perl,
Python,and others.
I am a pretty noob programmer yet, but I am having just a few issues to get things started with C and Glade. So I guess you will run smoothly here with your snake. Take a look.

embedding plot within Qt gui

How do you embed a vpython plot (animated) within your Qt GUI? so that it has its own display area and would not need to created a new window anymore.
vpython's FAQs claim that vpython's architecture make any embedding a problem...:
Q: Is there a way to embed VPython in another environment?
This is difficult because VPython has
two threads, your computational thread
and a rendering thread which about 25
times per second paints the scene
using the current attributes of the
graphics objects. However, Stef
Mientki has managed to embed VPython
in a wxPython window on Windows; see
the contributed section.
So if with wxPython it takes heroic efforts ("has managed to" doesn't sound like a trivial achievement;-) AND only works on a single platform, I fear it won't be any easier with Qt... one hard, uphill slog separately on each and every single platform.
If you're up for a SERIOUS challenge, deeply familiar with vpython, reasonably familiar with Qt, and acquainted with the underlying window-level architecture on all platforms you care about (and with a minor in wxPython), the place to start is Mientki's amazing contribution. He's actually working well below wxPython's level of abstraction, and in terms of win32gui calls, win32con constants, plus "a finite state-machine, clocked by a wx.Timer" at 100 milliseconds (though he does admit that the result from the latter Frankenstein surgery is... "not perfect";-). Extremely similar approaches should see you home (in a similarly "not perfect" way) on any other framework on Windows, including Qt.
However, nobody's yet offered any ports of this to Mac OS X, nor to any window manager of the many that are popular on Linux and Unix-like architectures (I'm not sure whether the feat could be achieved just at xlib level -- window decoration aspects do seem to be involved, and in the X11 world those DO tend to need window manager cooperation).
So, the literal answer to your question is, "with a huge amount of work requiring lots of skills and/or incredible perseverance, and probably in a platform-dependent way that will require redoing on each and every platform of interest"... sorry to be the bearer of pretty bad news, but I prefer to call them as I see them.
I contacted maintainer of VPython and he confirmed, that he is not aware of any working solution where Visual is embedded into QT window.
That turned me to try VTK and so far I'm pretty happy, no problem with using VTK within PyQT framework.

Categories

Resources