• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1:tocdepth: 2
2
3==========================
4Graphic User Interface FAQ
5==========================
6
7.. only:: html
8
9   .. contents::
10
11What platform-independent GUI toolkits exist for Python?
12========================================================
13
14Depending on what platform(s) you are aiming at, there are several.
15
16.. XXX check links
17
18Tkinter
19-------
20
21Standard builds of Python include an object-oriented interface to the Tcl/Tk
22widget set, called Tkinter.  This is probably the easiest to install and use.
23For more info about Tk, including pointers to the source, see the Tcl/Tk home
24page at https://www.tcl.tk.  Tcl/Tk is fully portable to the Mac OS X, Windows,
25and Unix platforms.
26
27wxWidgets
28---------
29
30wxWidgets (https://www.wxwidgets.org) is a free, portable GUI class
31library written in C++ that provides a native look and feel on a
32number of platforms, with Windows, Mac OS X, GTK, X11, all listed as
33current stable targets.  Language bindings are available for a number
34of languages including Python, Perl, Ruby, etc.
35
36wxPython (http://www.wxpython.org) is the Python binding for
37wxwidgets.  While it often lags slightly behind the official wxWidgets
38releases, it also offers a number of features via pure Python
39extensions that are not available in other language bindings.  There
40is an active wxPython user and developer community.
41
42Both wxWidgets and wxPython are free, open source, software with
43permissive licences that allow their use in commercial products as
44well as in freeware or shareware.
45
46
47Qt
48---
49
50There are bindings available for the Qt toolkit (using either `PyQt
51<https://riverbankcomputing.com/software/pyqt/intro>`_ or `PySide
52<https://wiki.qt.io/PySide>`_) and for KDE (`PyKDE4 <https://techbase.kde.org/Languages/Python/Using_PyKDE_4>`__).
53PyQt is currently more mature than PySide, but you must buy a PyQt license from
54`Riverbank Computing <https://www.riverbankcomputing.com/commercial/license-faq>`_
55if you want to write proprietary applications.  PySide is free for all applications.
56
57Qt 4.5 upwards is licensed under the LGPL license; also, commercial licenses
58are available from `The Qt Company <https://www.qt.io/licensing/>`_.
59
60Gtk+
61----
62
63PyGtk bindings for the `Gtk+ toolkit <http://www.gtk.org>`_ have been
64implemented by James Henstridge; see <http://www.pygtk.org>.
65
66FLTK
67----
68
69Python bindings for `the FLTK toolkit <http://www.fltk.org>`_, a simple yet
70powerful and mature cross-platform windowing system, are available from `the
71PyFLTK project <http://pyfltk.sourceforge.net>`_.
72
73
74FOX
75----
76
77A wrapper for `the FOX toolkit <http://www.fox-toolkit.org/>`_ called `FXpy
78<http://fxpy.sourceforge.net/>`_ is available.  FOX supports both Unix variants
79and Windows.
80
81
82OpenGL
83------
84
85For OpenGL bindings, see `PyOpenGL <http://pyopengl.sourceforge.net>`_.
86
87
88What platform-specific GUI toolkits exist for Python?
89========================================================
90
91By installing the `PyObjc Objective-C bridge
92<https://pythonhosted.org/pyobjc/>`_, Python programs can use Mac OS X's
93Cocoa libraries.
94
95:ref:`Pythonwin <windows-faq>` by Mark Hammond includes an interface to the
96Microsoft Foundation Classes and a Python programming environment
97that's written mostly in Python using the MFC classes.
98
99
100Tkinter questions
101=================
102
103How do I freeze Tkinter applications?
104-------------------------------------
105
106Freeze is a tool to create stand-alone applications.  When freezing Tkinter
107applications, the applications will not be truly stand-alone, as the application
108will still need the Tcl and Tk libraries.
109
110One solution is to ship the application with the Tcl and Tk libraries, and point
111to them at run-time using the :envvar:`TCL_LIBRARY` and :envvar:`TK_LIBRARY`
112environment variables.
113
114To get truly stand-alone applications, the Tcl scripts that form the library
115have to be integrated into the application as well. One tool supporting that is
116SAM (stand-alone modules), which is part of the Tix distribution
117(http://tix.sourceforge.net/).
118
119Build Tix with SAM enabled, perform the appropriate call to
120:c:func:`Tclsam_init`, etc. inside Python's
121:file:`Modules/tkappinit.c`, and link with libtclsam and libtksam (you
122might include the Tix libraries as well).
123
124
125Can I have Tk events handled while waiting for I/O?
126---------------------------------------------------
127
128On platforms other than Windows, yes, and you don't even
129need threads!  But you'll have to restructure your I/O
130code a bit.  Tk has the equivalent of Xt's :c:func:`XtAddInput()` call, which allows you
131to register a callback function which will be called from the Tk mainloop when
132I/O is possible on a file descriptor.  See :ref:`tkinter-file-handlers`.
133
134
135I can't get key bindings to work in Tkinter: why?
136-------------------------------------------------
137
138An often-heard complaint is that event handlers bound to events with the
139:meth:`bind` method don't get handled even when the appropriate key is pressed.
140
141The most common cause is that the widget to which the binding applies doesn't
142have "keyboard focus".  Check out the Tk documentation for the focus command.
143Usually a widget is given the keyboard focus by clicking in it (but not for
144labels; see the takefocus option).
145
146
147
148