• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
49Various third-party freeze libraries such as py2exe and cx_Freeze have
50handling for Tkinter applications built-in.
51
52
53Can I have Tk events handled while waiting for I/O?
54---------------------------------------------------
55
56On platforms other than Windows, yes, and you don't even
57need threads!  But you'll have to restructure your I/O
58code a bit.  Tk has the equivalent of Xt's :c:func:`!XtAddInput` call, which allows you
59to register a callback function which will be called from the Tk mainloop when
60I/O is possible on a file descriptor.  See :ref:`tkinter-file-handlers`.
61
62
63I can't get key bindings to work in Tkinter: why?
64-------------------------------------------------
65
66An often-heard complaint is that event handlers :ref:`bound <bindings-and-events>`
67to events with the :meth:`!bind` method
68don't get handled even when the appropriate key is pressed.
69
70The most common cause is that the widget to which the binding applies doesn't
71have "keyboard focus".  Check out the Tk documentation for the focus command.
72Usually a widget is given the keyboard focus by clicking in it (but not for
73labels; see the takefocus option).
74