Graphic User Interface FAQ¶
General GUI Questions¶
What GUI toolkits exist for Python?¶
Standard builds of Python include an object-oriented interface to the Tcl/Tkwidget set, calledtkinter. This is probably the easiest toinstall (since it comes included with mostbinary distributions of Python) and use.For more info about Tk, including pointers to the source, see theTcl/Tk home page. Tcl/Tk is fully portable to themacOS, Windows, and Unix platforms.
Depending on what platform(s) you are aiming at, there are also severalalternatives. Alist of cross-platform andplatform-specific GUIframeworks can be found on the python wiki.
Tkinter questions¶
How do I freeze Tkinter applications?¶
Freeze is a tool to create stand-alone applications. When freezing Tkinterapplications, the applications will not be truly stand-alone, as the applicationwill still need the Tcl and Tk libraries.
One solution is to ship the application with the Tcl and Tk libraries, and pointto them at run-time using theTCL_LIBRARY andTK_LIBRARYenvironment variables.
Various third-party freeze libraries such as py2exe and cx_Freeze havehandling for Tkinter applications built-in.
Can I have Tk events handled while waiting for I/O?¶
On platforms other than Windows, yes, and you don’t evenneed threads! But you’ll have to restructure your I/Ocode a bit. Tk has the equivalent of Xt’sXtAddInput() call, which allows youto register a callback function which will be called from the Tk mainloop whenI/O is possible on a file descriptor. SeeFile Handlers.
I can’t get key bindings to work in Tkinter: why?¶
An often-heard complaint is that event handlersboundto events with thebind() methoddon’t get handled even when the appropriate key is pressed.
The most common cause is that the widget to which the binding applies doesn’thave “keyboard focus”. Check out the Tk documentation for the focus command.Usually a widget is given the keyboard focus by clicking in it (but not forlabels; see the takefocus option).