内容表

  • 图形用户接口 FAQ
    • General GUI Questions
    • What GUI toolkits exist for Python?
    • 就业培训     下载中心     Wiki     联络
      登录   注册

      Log
      1. 首页
      2. Python 3.12.4
      3. 索引
      4. 模块
      5. 下一
      6. 上一
      7. Python FAQ (常见问题)
      8. 图形用户接口 FAQ

      图形用户接口 FAQ ¶

      内容

      • 图形用户接口 FAQ

        • General GUI Questions

        • What GUI toolkits exist for Python?

        • Tkinter questions

          • How do I freeze Tkinter applications?

          • Can I have Tk events handled while waiting for I/O?

          • I can’t get key bindings to work in Tkinter: why?

      General GUI Questions ¶

      What GUI toolkits exist for Python? ¶

      Standard builds of Python include an object-oriented interface to the Tcl/Tk widget set, called tkinter . This is probably the easiest to install (since it comes included with most binary distributions of Python) and use. For more info about Tk, including pointers to the source, see the Tcl/Tk home page . Tcl/Tk is fully portable to the macOS, Windows, and Unix platforms.

      Depending on what platform(s) you are aiming at, there are also several alternatives. A list of cross-platform and platform-specific GUI frameworks can be found on the python wiki.

      Tkinter questions ¶

      How do I freeze Tkinter applications? ¶

      Freeze is a tool to create stand-alone applications. When freezing Tkinter applications, the applications will not be truly stand-alone, as the application will still need the Tcl and Tk libraries.

      One solution is to ship the application with the Tcl and Tk libraries, and point to them at run-time using the TCL_LIBRARY and TK_LIBRARY 环境变量。

      To get truly stand-alone applications, the Tcl scripts that form the library have to be integrated into the application as well. One tool supporting that is SAM (stand-alone modules), which is part of the Tix distribution ( https://tix.sourceforge.net/ ).

      Build Tix with SAM enabled, perform the appropriate call to Tclsam_init() , etc. inside Python’s Modules/tkappinit.c , and link with libtclsam and libtksam (you might include the Tix libraries as well).

      Can I have Tk events handled while waiting for I/O? ¶

      On platforms other than Windows, yes, and you don’t even need threads! But you’ll have to restructure your I/O code a bit. Tk has the equivalent of Xt’s XtAddInput() call, which allows you to register a callback function which will be called from the Tk mainloop when I/O is possible on a file descriptor. See File Handlers .

      I can’t get key bindings to work in Tkinter: why? ¶

      An often-heard complaint is that event handlers bound to events with the bind() method don’t get handled even when the appropriate key is pressed.

      The most common cause is that the widget to which the binding applies doesn’t have “keyboard focus”. Check out the Tk documentation for the focus command. Usually a widget is given the keyboard focus by clicking in it (but not for labels; see the takefocus option).

      内容表

      • 图形用户接口 FAQ
        • General GUI Questions
        • What GUI toolkits exist for Python?
        • Tkinter questions

      上一话题

      Python 在 Windows FAQ

      下一话题

      FAQ:为什么要在我的计算机中安装 Python?

      本页

      • 报告 Bug
      • 展示源

      快速搜索

      键入搜索术语或模块、类、函数名称。

      1. 首页
      2. Python 3.12.4
      3. 索引
      4. 模块
      5. 下一
      6. 上一
      7. Python FAQ (常见问题)
      8. 图形用户接口 FAQ

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1