# 24. Tk图形用户界面(GUI)

Tk/Tcl has long been an integral part of Python. It provides a robust and platform independent windowing toolkit, that is available to Python programmers using the `Tkinter` module, and its extensions, the `Tix` and the `ttk` modules.

The `Tkinter` module is a thin object-oriented layer on top of Tcl/Tk. To use `Tkinter`, you don’t need to write Tcl code, but you will need to consult the Tk documentation, and occasionally the Tcl documentation. `Tkinter` is a set of wrappers that implement the Tk widgets as Python classes. In addition, the internal module `_tkinter` provides a threadsafe mechanism which allows Python and Tcl to interact.

`Tkinter`’s chief virtues are that it is fast, and that it usually comes bundled with Python. Although its standard documentation is weak, good material is available, which includes: references, tutorials, a book and others. `Tkinter` is also famous for having an outdated look and feel, which has been vastly improved in Tk 8.5. Nevertheless, there are many other GUI libraries that you could be interested in. For more information about alternatives, see the 其他图形用户界面（GUI）包 section.

- 24.1. `Tkinter` — Python interface to Tcl/Tk
  - 24.1.1. Tkinter 模块
  - 24.1.2. Tkinter Life Preserver
    - 24.1.2.1. How To Use This Section
    - 24.1.2.2. A Simple Hello World Program
  - 24.1.3. A (Very) Quick Look at Tcl/Tk
  - 24.1.4. Mapping Basic Tk into Tkinter
  - 24.1.5. How Tk and Tkinter are Related
  - 24.1.6. Handy Reference
    - 24.1.6.1. Setting Options
    - 24.1.6.2. The Packer
    - 24.1.6.3. Packer Options
    - 24.1.6.4. Coupling Widget Variables
    - 24.1.6.5. The Window Manager
    - 24.1.6.6. Tk Option Data Types
    - 24.1.6.7. Bindings and Events
    - 24.1.6.8. The index Parameter
    - 24.1.6.9. Images
  - 24.1.7. File Handlers
- 24.2. `ttk` — Tk themed widgets
  - 24.2.1. Using Ttk
  - 24.2.2. Ttk Widgets
  - 24.2.3. Widget
    - 24.2.3.1. Standard Options
    - 24.2.3.2. Scrollable Widget Options
    - 24.2.3.3. Label Options
    - 24.2.3.4. Compatibility Options
    - 24.2.3.5. Widget States
    - 24.2.3.6. ttk.Widget
  - 24.2.4. Combobox
    - 24.2.4.1. Options
    - 24.2.4.2. Virtual events
    - 24.2.4.3. ttk.Combobox
  - 24.2.5. Notebook
    - 24.2.5.1. Options
    - 24.2.5.2. Tab Options
    - 24.2.5.3. Tab Identifiers
    - 24.2.5.4. Virtual Events
    - 24.2.5.5. ttk.Notebook
  - 24.2.6. Progressbar
    - 24.2.6.1. Options
    - 24.2.6.2. ttk.Progressbar
  - 24.2.7. Separator
    - 24.2.7.1. Options
  - 24.2.8. Sizegrip
    - 24.2.8.1. Platform-specific notes
    - 24.2.8.2. Bugs
  - 24.2.9. Treeview
    - 24.2.9.1. Options
    - 24.2.9.2. Item Options
    - 24.2.9.3. Tag Options
    - 24.2.9.4. Column Identifiers
    - 24.2.9.5. Virtual Events
    - 24.2.9.6. ttk.Treeview
  - 24.2.10. Ttk Styling
    - 24.2.10.1. Layouts
- 24.3. `Tix` — Extension widgets for Tk
  - 24.3.1. Using Tix
  - 24.3.2. Tix Widgets
    - 24.3.2.1. Basic Widgets
    - 24.3.2.2. File Selectors
    - 24.3.2.3. Hierarchical ListBox
    - 24.3.2.4. Tabular ListBox
    - 24.3.2.5. Manager Widgets
    - 24.3.2.6. Image Types
    - 24.3.2.7. Miscellaneous Widgets
    - 24.3.2.8. Form Geometry Manager
  - 24.3.3. Tix Commands
- 24.4. `ScrolledText` — Scrolled Text Widget
- 24.5. `turtle` — Turtle graphics for Tk
  - 24.5.1. 概述
  - 24.5.2. Overview over available Turtle and Screen methods
    - 24.5.2.1. Turtle 方法
    - 24.5.2.2. TurtleScreen/Screen 方法
  - 24.5.3. RawTurtle/Turtle 方法和对应函数
    - 24.5.3.1. 海龟动作
    - 24.5.3.2. 获取海龟的状态
    - 24.5.3.3. 度量单位设置
    - 24.5.3.4. 画笔控制
      - 24.5.3.4.1. 绘图状态
      - 24.5.3.4.2. 颜色控制
      - 24.5.3.4.3. 填充
      - 24.5.3.4.4. 更多绘图控制
    - 24.5.3.5. 海龟状态
      - 24.5.3.5.1. 可见性
      - 24.5.3.5.2. 外观
    - 24.5.3.6. 使用事件
    - 24.5.3.7. 特殊海龟方法
    - 24.5.3.8. Excursus about the use of compound shapes
  - 24.5.4. TurtleScreen/Screen 方法及对应函数
    - 24.5.4.1. 窗口控制
    - 24.5.4.2. 动画控制
    - 24.5.4.3. 使用屏幕事件
    - 24.5.4.4. 设置与特殊方法
    - 24.5.4.5. Screen 专有方法, 而非继承自 TurtleScreen
  - 24.5.5. The public classes of the module `turtle`
  - 24.5.6. 帮助与配置
    - 24.5.6.1. 如何使用帮助
    - 24.5.6.2. 文档字符串翻译为不同的语言
    - 24.5.6.3. 如何配置 Screen 和 Turtle
  - 24.5.7. Demo scripts
- 24.6. IDLE
  - 24.6.1. 目录
    - 24.6.1.1. 文件目录 （命令行和编辑器）
    - 24.6.1.2. 编辑目录（命令行和编辑器）
    - 24.6.1.3. 格式菜单（仅 window 编辑器）
    - 24.6.1.4. 运行菜单（仅 window 编辑器）
    - 24.6.1.5. Shell 菜单（仅 window 编辑器）
    - 24.6.1.6. 调试菜单（仅 window 编辑器）
    - 24.6.1.7. 选项菜单（命令行和编辑器）
    - 24.6.1.8. Window 菜单（命令行和编辑器）
    - 24.6.1.9. 帮助菜单（命令行和编辑器）
    - 24.6.1.10. 上下文菜单
  - 24.6.2. 编辑和导航
    - 24.6.2.1. 自动缩进
    - 24.6.2.2. 完成
    - 24.6.2.3. 提示
    - 24.6.2.4. Python Shell 窗口
    - 24.6.2.5. 文本颜色
  - 24.6.3. 启动和代码执行
    - 24.6.3.1. 命令行语法
    - 24.6.3.2. IDLE-console differences
    - 24.6.3.3. 在没有子进程的情况下运行
  - 24.6.4. 帮助和偏好
    - 24.6.4.1. Additional help sources
    - 24.6.4.2. 偏好设定
    - 24.6.4.3. 扩展
- 24.7. 其他图形用户界面（GUI）包