17db96d56Sopenharmony_ci:tocdepth: 2 27db96d56Sopenharmony_ci 37db96d56Sopenharmony_ci========================== 47db96d56Sopenharmony_ciGraphic User Interface FAQ 57db96d56Sopenharmony_ci========================== 67db96d56Sopenharmony_ci 77db96d56Sopenharmony_ci.. only:: html 87db96d56Sopenharmony_ci 97db96d56Sopenharmony_ci .. contents:: 107db96d56Sopenharmony_ci 117db96d56Sopenharmony_ci.. XXX need review for Python 3. 127db96d56Sopenharmony_ci 137db96d56Sopenharmony_ci 147db96d56Sopenharmony_ciGeneral GUI Questions 157db96d56Sopenharmony_ci===================== 167db96d56Sopenharmony_ci 177db96d56Sopenharmony_ciWhat GUI toolkits exist for Python? 187db96d56Sopenharmony_ci=================================== 197db96d56Sopenharmony_ci 207db96d56Sopenharmony_ciStandard builds of Python include an object-oriented interface to the Tcl/Tk 217db96d56Sopenharmony_ciwidget set, called :ref:`tkinter <Tkinter>`. This is probably the easiest to 227db96d56Sopenharmony_ciinstall (since it comes included with most 237db96d56Sopenharmony_ci`binary distributions <https://www.python.org/downloads/>`_ of Python) and use. 247db96d56Sopenharmony_ciFor more info about Tk, including pointers to the source, see the 257db96d56Sopenharmony_ci`Tcl/Tk home page <https://www.tcl.tk>`_. Tcl/Tk is fully portable to the 267db96d56Sopenharmony_cimacOS, Windows, and Unix platforms. 277db96d56Sopenharmony_ci 287db96d56Sopenharmony_ciDepending on what platform(s) you are aiming at, there are also several 297db96d56Sopenharmony_cialternatives. A `list of cross-platform 307db96d56Sopenharmony_ci<https://wiki.python.org/moin/GuiProgramming#Cross-Platform_Frameworks>`_ and 317db96d56Sopenharmony_ci`platform-specific 327db96d56Sopenharmony_ci<https://wiki.python.org/moin/GuiProgramming#Platform-specific_Frameworks>`_ GUI 337db96d56Sopenharmony_ciframeworks can be found on the python wiki. 347db96d56Sopenharmony_ci 357db96d56Sopenharmony_ciTkinter questions 367db96d56Sopenharmony_ci================= 377db96d56Sopenharmony_ci 387db96d56Sopenharmony_ciHow do I freeze Tkinter applications? 397db96d56Sopenharmony_ci------------------------------------- 407db96d56Sopenharmony_ci 417db96d56Sopenharmony_ciFreeze is a tool to create stand-alone applications. When freezing Tkinter 427db96d56Sopenharmony_ciapplications, the applications will not be truly stand-alone, as the application 437db96d56Sopenharmony_ciwill still need the Tcl and Tk libraries. 447db96d56Sopenharmony_ci 457db96d56Sopenharmony_ciOne solution is to ship the application with the Tcl and Tk libraries, and point 467db96d56Sopenharmony_cito them at run-time using the :envvar:`TCL_LIBRARY` and :envvar:`TK_LIBRARY` 477db96d56Sopenharmony_cienvironment variables. 487db96d56Sopenharmony_ci 497db96d56Sopenharmony_ciTo get truly stand-alone applications, the Tcl scripts that form the library 507db96d56Sopenharmony_cihave to be integrated into the application as well. One tool supporting that is 517db96d56Sopenharmony_ciSAM (stand-alone modules), which is part of the Tix distribution 527db96d56Sopenharmony_ci(https://tix.sourceforge.net/). 537db96d56Sopenharmony_ci 547db96d56Sopenharmony_ciBuild Tix with SAM enabled, perform the appropriate call to 557db96d56Sopenharmony_ci:c:func:`Tclsam_init`, etc. inside Python's 567db96d56Sopenharmony_ci:file:`Modules/tkappinit.c`, and link with libtclsam and libtksam (you 577db96d56Sopenharmony_cimight include the Tix libraries as well). 587db96d56Sopenharmony_ci 597db96d56Sopenharmony_ci 607db96d56Sopenharmony_ciCan I have Tk events handled while waiting for I/O? 617db96d56Sopenharmony_ci--------------------------------------------------- 627db96d56Sopenharmony_ci 637db96d56Sopenharmony_ciOn platforms other than Windows, yes, and you don't even 647db96d56Sopenharmony_cineed threads! But you'll have to restructure your I/O 657db96d56Sopenharmony_cicode a bit. Tk has the equivalent of Xt's :c:func:`XtAddInput()` call, which allows you 667db96d56Sopenharmony_cito register a callback function which will be called from the Tk mainloop when 677db96d56Sopenharmony_ciI/O is possible on a file descriptor. See :ref:`tkinter-file-handlers`. 687db96d56Sopenharmony_ci 697db96d56Sopenharmony_ci 707db96d56Sopenharmony_ciI can't get key bindings to work in Tkinter: why? 717db96d56Sopenharmony_ci------------------------------------------------- 727db96d56Sopenharmony_ci 737db96d56Sopenharmony_ciAn often-heard complaint is that event handlers bound to events with the 747db96d56Sopenharmony_ci:meth:`bind` method don't get handled even when the appropriate key is pressed. 757db96d56Sopenharmony_ci 767db96d56Sopenharmony_ciThe most common cause is that the widget to which the binding applies doesn't 777db96d56Sopenharmony_cihave "keyboard focus". Check out the Tk documentation for the focus command. 787db96d56Sopenharmony_ciUsually a widget is given the keyboard focus by clicking in it (but not for 797db96d56Sopenharmony_cilabels; see the takefocus option). 80