1:tocdepth: 2 2 3========================== 4Graphic User Interface FAQ 5========================== 6 7.. only:: html 8 9 .. contents:: 10 11.. XXX need review for Python 3. 12 13 14General GUI Questions 15===================== 16 17What GUI toolkits exist for Python? 18=================================== 19 20Standard builds of Python include an object-oriented interface to the Tcl/Tk 21widget set, called :ref:`tkinter <Tkinter>`. This is probably the easiest to 22install (since it comes included with most 23`binary distributions <https://www.python.org/downloads/>`_ of Python) and use. 24For more info about Tk, including pointers to the source, see the 25`Tcl/Tk home page <https://www.tcl.tk>`_. Tcl/Tk is fully portable to the 26macOS, Windows, and Unix platforms. 27 28Depending on what platform(s) you are aiming at, there are also several 29alternatives. A `list of cross-platform 30<https://wiki.python.org/moin/GuiProgramming#Cross-Platform_Frameworks>`_ and 31`platform-specific 32<https://wiki.python.org/moin/GuiProgramming#Platform-specific_Frameworks>`_ GUI 33frameworks can be found on the python wiki. 34 35Tkinter questions 36================= 37 38How do I freeze Tkinter applications? 39------------------------------------- 40 41Freeze is a tool to create stand-alone applications. When freezing Tkinter 42applications, the applications will not be truly stand-alone, as the application 43will still need the Tcl and Tk libraries. 44 45One solution is to ship the application with the Tcl and Tk libraries, and point 46to them at run-time using the :envvar:`TCL_LIBRARY` and :envvar:`TK_LIBRARY` 47environment variables. 48 49To get truly stand-alone applications, the Tcl scripts that form the library 50have to be integrated into the application as well. One tool supporting that is 51SAM (stand-alone modules), which is part of the Tix distribution 52(http://tix.sourceforge.net/). 53 54Build Tix with SAM enabled, perform the appropriate call to 55:c:func:`Tclsam_init`, etc. inside Python's 56:file:`Modules/tkappinit.c`, and link with libtclsam and libtksam (you 57might include the Tix libraries as well). 58 59 60Can I have Tk events handled while waiting for I/O? 61--------------------------------------------------- 62 63On platforms other than Windows, yes, and you don't even 64need threads! But you'll have to restructure your I/O 65code a bit. Tk has the equivalent of Xt's :c:func:`XtAddInput()` call, which allows you 66to register a callback function which will be called from the Tk mainloop when 67I/O is possible on a file descriptor. See :ref:`tkinter-file-handlers`. 68 69 70I can't get key bindings to work in Tkinter: why? 71------------------------------------------------- 72 73An often-heard complaint is that event handlers bound to events with the 74:meth:`bind` method don't get handled even when the appropriate key is pressed. 75 76The most common cause is that the widget to which the binding applies doesn't 77have "keyboard focus". Check out the Tk documentation for the focus command. 78Usually a widget is given the keyboard focus by clicking in it (but not for 79labels; see the takefocus option). 80