2009-10-11 15:31:23 -03:00
|
|
|
:tocdepth: 2
|
|
|
|
|
|
|
|
==========================
|
|
|
|
Graphic User Interface FAQ
|
|
|
|
==========================
|
|
|
|
|
2013-03-28 09:28:44 -03:00
|
|
|
.. only:: html
|
|
|
|
|
|
|
|
.. contents::
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
What platform-independent GUI toolkits exist for Python?
|
2010-05-27 10:30:09 -03:00
|
|
|
========================================================
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
Depending on what platform(s) you are aiming at, there are several.
|
|
|
|
|
|
|
|
.. XXX check links
|
|
|
|
|
|
|
|
Tkinter
|
2010-05-27 10:30:09 -03:00
|
|
|
-------
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
Standard builds of Python include an object-oriented interface to the Tcl/Tk
|
|
|
|
widget set, called Tkinter. This is probably the easiest to install and use.
|
|
|
|
For more info about Tk, including pointers to the source, see the Tcl/Tk home
|
2014-04-12 13:31:28 -03:00
|
|
|
page at http://www.tcl.tk. Tcl/Tk is fully portable to the Mac OS X, Windows,
|
|
|
|
and Unix platforms.
|
2009-10-11 15:31:23 -03:00
|
|
|
|
2009-10-13 13:11:49 -03:00
|
|
|
wxWidgets
|
2010-05-27 10:30:09 -03:00
|
|
|
---------
|
2009-10-11 15:31:23 -03:00
|
|
|
|
2010-05-27 10:22:53 -03:00
|
|
|
wxWidgets (http://www.wxwidgets.org) is a free, portable GUI class
|
|
|
|
library written in C++ that provides a native look and feel on a
|
2014-04-12 13:31:28 -03:00
|
|
|
number of platforms, with Windows, Mac OS X, GTK, X11, all listed as
|
2010-05-27 10:22:53 -03:00
|
|
|
current stable targets. Language bindings are available for a number
|
|
|
|
of languages including Python, Perl, Ruby, etc.
|
|
|
|
|
|
|
|
wxPython (http://www.wxpython.org) is the Python binding for
|
|
|
|
wxwidgets. While it often lags slightly behind the official wxWidgets
|
|
|
|
releases, it also offers a number of features via pure Python
|
|
|
|
extensions that are not available in other language bindings. There
|
|
|
|
is an active wxPython user and developer community.
|
|
|
|
|
|
|
|
Both wxWidgets and wxPython are free, open source, software with
|
|
|
|
permissive licences that allow their use in commercial products as
|
|
|
|
well as in freeware or shareware.
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
|
|
|
|
Qt
|
2010-05-27 10:30:09 -03:00
|
|
|
---
|
2009-10-11 15:31:23 -03:00
|
|
|
|
2013-10-05 19:02:09 -03:00
|
|
|
There are bindings available for the Qt toolkit (using either `PyQt
|
2014-10-29 06:57:37 -03:00
|
|
|
<http://www.riverbankcomputing.co.uk/software/pyqt/intro>`_ or `PySide
|
2014-10-29 05:24:54 -03:00
|
|
|
<http://www.pyside.org/>`_) and for KDE (`PyKDE <https://techbase.kde.org/Development/Languages/Python>`__).
|
2013-10-05 19:02:09 -03:00
|
|
|
PyQt is currently more mature than PySide, but you must buy a PyQt license from
|
|
|
|
`Riverbank Computing <http://www.riverbankcomputing.co.uk/software/pyqt/license>`_
|
|
|
|
if you want to write proprietary applications. PySide is free for all applications.
|
|
|
|
|
|
|
|
Qt 4.5 upwards is licensed under the LGPL license; also, commercial licenses
|
2014-10-29 05:24:54 -03:00
|
|
|
are available from `The Qt Company <http://www.qt.io/licensing/>`_.
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
Gtk+
|
2010-05-27 10:30:09 -03:00
|
|
|
----
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
PyGtk bindings for the `Gtk+ toolkit <http://www.gtk.org>`_ have been
|
2009-10-13 13:11:49 -03:00
|
|
|
implemented by James Henstridge; see <http://www.pygtk.org>.
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
FLTK
|
2010-05-27 10:30:09 -03:00
|
|
|
----
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
Python bindings for `the FLTK toolkit <http://www.fltk.org>`_, a simple yet
|
|
|
|
powerful and mature cross-platform windowing system, are available from `the
|
|
|
|
PyFLTK project <http://pyfltk.sourceforge.net>`_.
|
|
|
|
|
|
|
|
|
|
|
|
FOX
|
2010-05-27 10:30:09 -03:00
|
|
|
----
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
A wrapper for `the FOX toolkit <http://www.fox-toolkit.org/>`_ called `FXpy
|
|
|
|
<http://fxpy.sourceforge.net/>`_ is available. FOX supports both Unix variants
|
|
|
|
and Windows.
|
|
|
|
|
|
|
|
|
|
|
|
OpenGL
|
2010-05-27 10:30:09 -03:00
|
|
|
------
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
For OpenGL bindings, see `PyOpenGL <http://pyopengl.sourceforge.net>`_.
|
|
|
|
|
|
|
|
|
|
|
|
What platform-specific GUI toolkits exist for Python?
|
2010-05-27 10:30:09 -03:00
|
|
|
========================================================
|
2009-10-11 15:31:23 -03:00
|
|
|
|
2009-10-13 13:11:49 -03:00
|
|
|
By installing the `PyObjc Objective-C bridge
|
2014-10-29 05:24:54 -03:00
|
|
|
<https://pythonhosted.org/pyobjc/>`_, Python programs can use Mac OS X's
|
2014-04-12 13:31:28 -03:00
|
|
|
Cocoa libraries.
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
:ref:`Pythonwin <windows-faq>` by Mark Hammond includes an interface to the
|
2009-10-13 13:11:49 -03:00
|
|
|
Microsoft Foundation Classes and a Python programming environment
|
|
|
|
that's written mostly in Python using the MFC classes.
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
|
|
|
|
Tkinter questions
|
|
|
|
=================
|
|
|
|
|
|
|
|
How do I freeze Tkinter applications?
|
|
|
|
-------------------------------------
|
|
|
|
|
|
|
|
Freeze is a tool to create stand-alone applications. When freezing Tkinter
|
|
|
|
applications, the applications will not be truly stand-alone, as the application
|
|
|
|
will still need the Tcl and Tk libraries.
|
|
|
|
|
2009-10-13 13:11:49 -03:00
|
|
|
One solution is to ship the application with the Tcl and Tk libraries, and point
|
2009-10-11 15:31:23 -03:00
|
|
|
to them at run-time using the :envvar:`TCL_LIBRARY` and :envvar:`TK_LIBRARY`
|
|
|
|
environment variables.
|
|
|
|
|
|
|
|
To get truly stand-alone applications, the Tcl scripts that form the library
|
|
|
|
have to be integrated into the application as well. One tool supporting that is
|
|
|
|
SAM (stand-alone modules), which is part of the Tix distribution
|
2009-10-13 13:11:49 -03:00
|
|
|
(http://tix.sourceforge.net/).
|
|
|
|
|
|
|
|
Build Tix with SAM enabled, perform the appropriate call to
|
2012-01-14 11:42:02 -04:00
|
|
|
:c:func:`Tclsam_init`, etc. inside Python's
|
2009-10-13 13:11:49 -03:00
|
|
|
:file:`Modules/tkappinit.c`, and link with libtclsam and libtksam (you
|
|
|
|
might include the Tix libraries as well).
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
|
|
|
|
Can I have Tk events handled while waiting for I/O?
|
|
|
|
---------------------------------------------------
|
|
|
|
|
2015-05-17 15:49:20 -03:00
|
|
|
On platforms other than Windows, yes, and you don't even
|
|
|
|
need threads! But you'll have to restructure your I/O
|
2012-01-14 11:42:02 -04:00
|
|
|
code a bit. Tk has the equivalent of Xt's :c:func:`XtAddInput()` call, which allows you
|
2009-10-11 15:31:23 -03:00
|
|
|
to register a callback function which will be called from the Tk mainloop when
|
2015-05-17 15:49:20 -03:00
|
|
|
I/O is possible on a file descriptor. See :ref:`tkinter-file-handlers`.
|
2009-10-11 15:31:23 -03:00
|
|
|
|
|
|
|
|
|
|
|
I can't get key bindings to work in Tkinter: why?
|
|
|
|
-------------------------------------------------
|
|
|
|
|
|
|
|
An often-heard complaint is that event handlers bound to events with the
|
|
|
|
:meth:`bind` method don't get handled even when the appropriate key is pressed.
|
|
|
|
|
|
|
|
The most common cause is that the widget to which the binding applies doesn't
|
|
|
|
have "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 for
|
|
|
|
labels; see the takefocus option).
|
|
|
|
|
|
|
|
|
|
|
|
|