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