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 73OpenGL 74------ 75 76For OpenGL bindings, see `PyOpenGL <http://pyopengl.sourceforge.net>`_. 77 78 79What platform-specific GUI toolkits exist for Python? 80======================================================== 81 82By installing the `PyObjc Objective-C bridge 83<https://pythonhosted.org/pyobjc/>`_, Python programs can use Mac OS X's 84Cocoa libraries. 85 86:ref:`Pythonwin <windows-faq>` by Mark Hammond includes an interface to the 87Microsoft Foundation Classes and a Python programming environment 88that's written mostly in Python using the MFC classes. 89 90 91Tkinter questions 92================= 93 94How do I freeze Tkinter applications? 95------------------------------------- 96 97Freeze is a tool to create stand-alone applications. When freezing Tkinter 98applications, the applications will not be truly stand-alone, as the application 99will still need the Tcl and Tk libraries. 100 101One solution is to ship the application with the Tcl and Tk libraries, and point 102to them at run-time using the :envvar:`TCL_LIBRARY` and :envvar:`TK_LIBRARY` 103environment variables. 104 105To get truly stand-alone applications, the Tcl scripts that form the library 106have to be integrated into the application as well. One tool supporting that is 107SAM (stand-alone modules), which is part of the Tix distribution 108(http://tix.sourceforge.net/). 109 110Build Tix with SAM enabled, perform the appropriate call to 111:c:func:`Tclsam_init`, etc. inside Python's 112:file:`Modules/tkappinit.c`, and link with libtclsam and libtksam (you 113might include the Tix libraries as well). 114 115 116Can I have Tk events handled while waiting for I/O? 117--------------------------------------------------- 118 119On platforms other than Windows, yes, and you don't even 120need threads! But you'll have to restructure your I/O 121code a bit. Tk has the equivalent of Xt's :c:func:`XtAddInput()` call, which allows you 122to register a callback function which will be called from the Tk mainloop when 123I/O is possible on a file descriptor. See :ref:`tkinter-file-handlers`. 124 125 126I can't get key bindings to work in Tkinter: why? 127------------------------------------------------- 128 129An often-heard complaint is that event handlers bound to events with the 130:meth:`bind` method don't get handled even when the appropriate key is pressed. 131 132The most common cause is that the widget to which the binding applies doesn't 133have "keyboard focus". Check out the Tk documentation for the focus command. 134Usually a widget is given the keyboard focus by clicking in it (but not for 135labels; see the takefocus option). 136 137 138 139