“Python/docs/3.9/library/tk”的版本间差异

来自菜鸟教程
Python/docs/3.9/library/tk
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:使用 Tk 的图形用户界面 — Python 文档}}
 
<div id="graphical-user-interfaces-with-tk" class="section">
 
<div id="graphical-user-interfaces-with-tk" class="section">
  
 
<span id="tkinter"></span>
 
<span id="tkinter"></span>
= Graphical User Interfaces with Tk =
+
= 使用 Tk 的图形用户界面 =
  
Tk/Tcl has long been an integral part of Python. It provides a robust and
+
Tk/Tcl 长期以来一直是 Python 不可或缺的一部分。 它提供了一个强大且与平台无关的窗口工具包,可供 Python 程序员使用 [[../tkinter#module-tkinter|tkinter]] 包及其扩展包 [[../tkinter.tix#module-tkinter|tkinter.tix]] tkinter.ttk[ X208X] 模块。
platform independent windowing toolkit, that is available to Python programmers
 
using the [[../tkinter#module-tkinter|<code>tkinter</code>]] package, and its extension, the [[../tkinter.tix#module-tkinter|<code>tkinter.tix</code>]] and
 
the [[../tkinter.ttk#module-tkinter|<code>tkinter.ttk</code>]] modules.
 
  
The [[../tkinter#module-tkinter|<code>tkinter</code>]] package is a thin object-oriented layer on top of Tcl/Tk. To
+
[[../tkinter#module-tkinter|tkinter]] 包是一个位于 Tcl/Tk 之上的面向对象的薄层。 要使用 [[../tkinter#module-tkinter|tkinter]],您不需要编写 Tcl 代码,但您需要查阅 Tk 文档,偶尔也需要查阅 Tcl 文档。 [[../tkinter#module-tkinter|tkinter]] 是一组将 Tk 小部件实现为 Python 类的包装器。
use [[../tkinter#module-tkinter|<code>tkinter</code>]], you don't need to write Tcl code, but you will need to
 
consult the Tk documentation, and occasionally the Tcl documentation.
 
[[../tkinter#module-tkinter|<code>tkinter</code>]] is a set of wrappers that implement the Tk widgets as Python
 
classes. In addition, the internal module <code>_tkinter</code> provides a threadsafe
 
mechanism which allows Python and Tcl to interact.
 
  
[[../tkinter#module-tkinter|<code>tkinter</code>]]'s chief virtues are that it is fast, and that it usually comes
+
[[../tkinter#module-tkinter|tkinter]] 的主要优点是速度快,而且通常与 Python 捆绑在一起。 虽然它的标准文档很薄弱,但有很好的材料可用,其中包括:参考资料、教程、一本书等。 [[../tkinter#module-tkinter|tkinter]] 也以过时的外观和感觉而闻名,这在 Tk 8.5 中得到了极大的改进。 不过,您可能会对许多其他 GUI 库感兴趣。 Python wiki 列出了几个替代的 [https://wiki.python.org/moin/GuiProgramming GUI 框架和工具]
bundled with Python. Although its standard documentation is weak, good
 
material is available, which includes: references, tutorials, a book and
 
others. [[../tkinter#module-tkinter|<code>tkinter</code>]] 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 [[../othergui#other-gui-packages|<span class="std std-ref">Other Graphical User Interface Packages</span>]] section.
 
  
 
<div class="toctree-wrapper compound">
 
<div class="toctree-wrapper compound">
  
* [[../tkinter|<code>tkinter</code> --- Python interface to Tcl/Tk]]
+
* [[../tkinter|<code>tkinter</code> Tcl/Tk 的 Python 接口]]
** [[../tkinter#tkinter-modules|Tkinter Modules]]
+
** [[../tkinter#tkinter-modules|Tkinter 模块]]
** [[../tkinter#tkinter-life-preserver|Tkinter Life Preserver]]
+
** [[../tkinter#tkinter-life-preserver|Tkinter 生命保护器]]
*** [[../tkinter#how-to-use-this-section|How To Use This Section]]
+
*** [[../tkinter#how-to-use-this-section|如何使用本节]]
*** [[../tkinter#a-simple-hello-world-program|A Simple Hello World Program]]
+
*** [[../tkinter#a-simple-hello-world-program|一个简单的 Hello World 程序]]
** [[../tkinter#a-very-quick-look-at-tcl-tk|A (Very) Quick Look at Tcl/Tk]]
+
** [[../tkinter#a-very-quick-look-at-tcl-tk|Tcl/Tk 的(非常)快速浏览]]
** [[../tkinter#mapping-basic-tk-into-tkinter|Mapping Basic Tk into Tkinter]]
+
** [[../tkinter#mapping-basic-tk-into-tkinter|将基本 Tk 映射到 Tkinter]]
** [[../tkinter#how-tk-and-tkinter-are-related|How Tk and Tkinter are Related]]
+
** [[../tkinter#how-tk-and-tkinter-are-related|Tk Tkinter 如何相关]]
** [[../tkinter#handy-reference|Handy Reference]]
+
** [[../tkinter#handy-reference|方便参考]]
*** [[../tkinter#setting-options|Setting Options]]
+
*** [[../tkinter#setting-options|设置选项]]
*** [[../tkinter#the-packer|The Packer]]
+
*** [[../tkinter#the-packer|包装工]]
*** [[../tkinter#packer-options|Packer Options]]
+
*** [[../tkinter#packer-options|封隔器选项]]
*** [[../tkinter#coupling-widget-variables|Coupling Widget Variables]]
+
*** [[../tkinter#coupling-widget-variables|耦合小部件变量]]
*** [[../tkinter#the-window-manager|The Window Manager]]
+
*** [[../tkinter#the-window-manager|窗口管理器]]
*** [[../tkinter#tk-option-data-types|Tk Option Data Types]]
+
*** [[../tkinter#tk-option-data-types|Tk 选项数据类型]]
*** [[../tkinter#bindings-and-events|Bindings and Events]]
+
*** [[../tkinter#bindings-and-events|绑定和事件]]
*** [[../tkinter#the-index-parameter|The index Parameter]]
+
*** [[../tkinter#the-index-parameter|索引参数]]
*** [[../tkinter#images|Images]]
+
*** [[../tkinter#images|图片]]
** [[../tkinter#file-handlers|File Handlers]]
+
** [[../tkinter#file-handlers|文件处理程序]]
* [[../tkinter.colorchooser|<code>tkinter.colorchooser</code> --- Color choosing dialog]]
+
* [[../tkinter.colorchooser|<code>tkinter.colorchooser</code> — 颜色选择对话框]]
* [[../tkinter.font|<code>tkinter.font</code> --- Tkinter font wrapper]]
+
* [[../tkinter.font|<code>tkinter.font</code> Tkinter 字体包装器]]
* [[../dialog|Tkinter Dialogs]]
+
* [[../dialog|Tkinter 对话框]]
** [[../dialog#module-tkinter|<code>tkinter.simpledialog</code> --- Standard Tkinter input dialogs]]
+
** [[../dialog#module-tkinter|<code>tkinter.simpledialog</code> — 标准 Tkinter 输入对话框]]
** [[../dialog#module-tkinter|<code>tkinter.filedialog</code> --- File selection dialogs]]
+
** [[../dialog#module-tkinter|<code>tkinter.filedialog</code> — 文件选择对话框]]
*** [[../dialog#native-load-save-dialogs|Native Load/Save Dialogs]]
+
*** [[../dialog#native-load-save-dialogs|本机加载/保存对话框]]
** [[../dialog#module-tkinter|<code>tkinter.commondialog</code> --- Dialog window templates]]
+
** [[../dialog#module-tkinter|<code>tkinter.commondialog</code> — 对话框窗口模板]]
* [[../tkinter.messagebox|<code>tkinter.messagebox</code> --- Tkinter message prompts]]
+
* [[../tkinter.messagebox|<code>tkinter.messagebox</code> Tkinter 消息提示]]
* [[../tkinter.scrolledtext|<code>tkinter.scrolledtext</code> --- Scrolled Text Widget]]
+
* [[../tkinter.scrolledtext|<code>tkinter.scrolledtext</code> — 滚动文本小部件]]
* [[../tkinter.dnd|<code>tkinter.dnd</code> --- Drag and drop support]]
+
* [[../tkinter.dnd|<code>tkinter.dnd</code> — 拖放支持]]
* [[../tkinter.ttk|<code>tkinter.ttk</code> --- Tk themed widgets]]
+
* [[../tkinter.ttk|<code>tkinter.ttk</code> Tk 主题小部件]]
** [[../tkinter|Using Ttk]]
+
** [[../tkinter|使用 Ttk]]
** [[../tkinter|Ttk Widgets]]
+
** [[../tkinter|Ttk 小工具]]
** [[../tkinter|Widget]]
+
** [[../tkinter|小工具]]
*** [[../tkinter|Standard Options]]
+
*** [[../tkinter|标准选项]]
*** [[../tkinter|Scrollable Widget Options]]
+
*** [[../tkinter|可滚动小部件选项]]
*** [[../tkinter|Label Options]]
+
*** [[../tkinter|标签选项]]
*** [[../tkinter|Compatibility Options]]
+
*** [[../tkinter|兼容性选项]]
*** [[../tkinter|Widget States]]
+
*** [[../tkinter|小部件状态]]
*** [[../tkinter|ttk.Widget]]
+
*** [[../tkinter|小工具]]
** [[../tkinter|Combobox]]
+
** [[../tkinter|组合框]]
*** [[../tkinter|Options]]
+
*** [[../tkinter|选项]]
*** [[../tkinter|Virtual events]]
+
*** [[../tkinter|虚拟活动]]
 
*** [[../tkinter|ttk.Combobox]]
 
*** [[../tkinter|ttk.Combobox]]
** [[../tkinter|Spinbox]]
+
** [[../tkinter|旋转箱]]
*** [[../tkinter|Options]]
+
*** [[../tkinter|选项]]
*** [[../tkinter|Virtual events]]
+
*** [[../tkinter|虚拟活动]]
*** [[../tkinter|ttk.Spinbox]]
+
*** [[../tkinter|ttk.spinbox]]
** [[../tkinter|Notebook]]
+
** [[../tkinter|笔记本]]
*** [[../tkinter|Options]]
+
*** [[../tkinter|选项]]
*** [[../tkinter|Tab Options]]
+
*** [[../tkinter|选项卡选项]]
*** [[../tkinter|Tab Identifiers]]
+
*** [[../tkinter|标签标识符]]
*** [[../tkinter|Virtual Events]]
+
*** [[../tkinter|虚拟活动]]
*** [[../tkinter|ttk.Notebook]]
+
*** [[../tkinter|ttk.笔记本]]
** [[../tkinter|Progressbar]]
+
** [[../tkinter|进度条]]
*** [[../tkinter|Options]]
+
*** [[../tkinter|选项]]
*** [[../tkinter|ttk.Progressbar]]
+
*** [[../tkinter|ttk.进度条]]
** [[../tkinter|Separator]]
+
** [[../tkinter|分隔器]]
*** [[../tkinter|Options]]
+
*** [[../tkinter|选项]]
** [[../tkinter|Sizegrip]]
+
** [[../tkinter|握把]]
*** [[../tkinter|Platform-specific notes]]
+
*** [[../tkinter|特定于平台的注释]]
*** [[../tkinter|Bugs]]
+
*** [[../tkinter|错误]]
** [[../tkinter|Treeview]]
+
** [[../tkinter|树视图]]
*** [[../tkinter|Options]]
+
*** [[../tkinter|选项]]
*** [[../tkinter|Item Options]]
+
*** [[../tkinter|项目选项]]
*** [[../tkinter|Tag Options]]
+
*** [[../tkinter|标签选项]]
*** [[../tkinter|Column Identifiers]]
+
*** [[../tkinter|列标识符]]
*** [[../tkinter|Virtual Events]]
+
*** [[../tkinter|虚拟活动]]
 
*** [[../tkinter|ttk.Treeview]]
 
*** [[../tkinter|ttk.Treeview]]
** [[../tkinter|Ttk Styling]]
+
** [[../tkinter|Ttk 造型]]
*** [[../tkinter|Layouts]]
+
*** [[../tkinter|布局]]
* [[../tkinter.tix|<code>tkinter.tix</code> --- Extension widgets for Tk]]
+
* [[../tkinter.tix|<code>tkinter.tix</code> Tk 的扩展小部件]]
** [[../tkinter|Using Tix]]
+
** [[../tkinter|使用 Tix]]
** [[../tkinter|Tix Widgets]]
+
** [[../tkinter|小工具]]
*** [[../tkinter|Basic Widgets]]
+
*** [[../tkinter|基本小工具]]
*** [[../tkinter|File Selectors]]
+
*** [[../tkinter|文件选择器]]
*** [[../tkinter|Hierarchical ListBox]]
+
*** [[../tkinter|分层列表框]]
*** [[../tkinter|Tabular ListBox]]
+
*** [[../tkinter|表格列表框]]
*** [[../tkinter|Manager Widgets]]
+
*** [[../tkinter|管理器小工具]]
*** [[../tkinter|Image Types]]
+
*** [[../tkinter|图像类型]]
*** [[../tkinter|Miscellaneous Widgets]]
+
*** [[../tkinter|杂项小工具]]
*** [[../tkinter|Form Geometry Manager]]
+
*** [[../tkinter|形状几何管理器]]
** [[../tkinter|Tix Commands]]
+
** [[../tkinter|Tix 命令]]
* [[../idle|IDLE]]
+
* [[../idle|闲置的]]
** [[../idle#menus|Menus]]
+
** [[../idle#menus|菜单]]
*** [[../idle#file-menu-shell-and-editor|File menu (Shell and Editor)]]
+
*** [[../idle#file-menu-shell-and-editor|文件菜单(Shell 和编辑器)]]
*** [[../idle#edit-menu-shell-and-editor|Edit menu (Shell and Editor)]]
+
*** [[../idle#edit-menu-shell-and-editor|编辑菜单(Shell 和编辑器)]]
*** [[../idle#format-menu-editor-window-only|Format menu (Editor window only)]]
+
*** [[../idle#format-menu-editor-window-only|格式菜单(仅限编辑器窗口)]]
*** [[../idle#run-menu-editor-window-only|Run menu (Editor window only)]]
+
*** [[../idle#run-menu-editor-window-only|运行菜单(仅限编辑器窗口)]]
*** [[../idle#shell-menu-shell-window-only|Shell menu (Shell window only)]]
+
*** [[../idle#shell-menu-shell-window-only|Shell 菜单(仅限 Shell 窗口)]]
*** [[../idle#debug-menu-shell-window-only|Debug menu (Shell window only)]]
+
*** [[../idle#debug-menu-shell-window-only|调试菜单(仅限 Shell 窗口)]]
*** [[../idle#options-menu-shell-and-editor|Options menu (Shell and Editor)]]
+
*** [[../idle#options-menu-shell-and-editor|选项菜单(Shell 和编辑器)]]
*** [[../idle#window-menu-shell-and-editor|Window menu (Shell and Editor)]]
+
*** [[../idle#window-menu-shell-and-editor|窗口菜单(Shell 和编辑器)]]
*** [[../idle#help-menu-shell-and-editor|Help menu (Shell and Editor)]]
+
*** [[../idle#help-menu-shell-and-editor|帮助菜单(Shell 和编辑器)]]
*** [[../idle#context-menus|Context Menus]]
+
*** [[../idle#context-menus|上下文菜单]]
** [[../idle#editing-and-navigation|Editing and navigation]]
+
** [[../idle#editing-and-navigation|编辑和导航]]
*** [[../idle#editor-windows|Editor windows]]
+
*** [[../idle#editor-windows|编辑器窗口]]
*** [[../idle#key-bindings|Key bindings]]
+
*** [[../idle#key-bindings|键绑定]]
*** [[../idle#automatic-indentation|Automatic indentation]]
+
*** [[../idle#automatic-indentation|自动缩进]]
*** [[../idle#completions|Completions]]
+
*** [[../idle#completions|完成]]
*** [[../idle#calltips|Calltips]]
+
*** [[../idle#calltips|提示]]
*** [[../idle#code-context|Code Context]]
+
*** [[../idle#code-context|代码上下文]]
*** [[../idle#python-shell-window|Python Shell window]]
+
*** [[../idle#python-shell-window|Python Shell 窗口]]
*** [[../idle#text-colors|Text colors]]
+
*** [[../idle#text-colors|文字颜色]]
** [[../idle#startup-and-code-execution|Startup and code execution]]
+
** [[../idle#startup-and-code-execution|启动和代码执行]]
*** [[../idle#command-line-usage|Command line usage]]
+
*** [[../idle#command-line-usage|命令行使用]]
*** [[../idle#startup-failure|Startup failure]]
+
*** [[../idle#startup-failure|启动失败]]
*** [[../idle#running-user-code|Running user code]]
+
*** [[../idle#running-user-code|运行用户代码]]
*** [[../idle#user-output-in-shell|User output in Shell]]
+
*** [[../idle#user-output-in-shell|Shell 中的用户输出]]
*** [[../idle#developing-tkinter-applications|Developing tkinter applications]]
+
*** [[../idle#developing-tkinter-applications|开发 tkinter 应用程序]]
*** [[../idle#running-without-a-subprocess|Running without a subprocess]]
+
*** [[../idle#running-without-a-subprocess|在没有子进程的情况下运行]]
** [[../idle#help-and-preferences|Help and preferences]]
+
** [[../idle#help-and-preferences|帮助和偏好]]
*** [[../idle#help-sources|Help sources]]
+
*** [[../idle#help-sources|帮助来源]]
*** [[../idle#setting-preferences|Setting preferences]]
+
*** [[../idle#setting-preferences|设置首选项]]
*** [[../idle#idle-on-macos|IDLE on macOS]]
+
*** [[../idle#idle-on-macos|macOS 上空闲]]
*** [[../idle#extensions|Extensions]]
+
*** [[../idle#extensions|扩展]]
* [[../othergui|Other Graphical User Interface Packages]]
 
  
  
第147行: 第133行:
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Python 3.9 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Python 3.9 文档]]

2021年10月31日 (日) 04:53的最新版本

使用 Tk 的图形用户界面

Tk/Tcl 长期以来一直是 Python 不可或缺的一部分。 它提供了一个强大且与平台无关的窗口工具包,可供 Python 程序员使用 tkinter 包及其扩展包 tkinter.tix 和 tkinter.ttk[ X208X] 模块。

tkinter 包是一个位于 Tcl/Tk 之上的面向对象的薄层。 要使用 tkinter,您不需要编写 Tcl 代码,但您需要查阅 Tk 文档,偶尔也需要查阅 Tcl 文档。 tkinter 是一组将 Tk 小部件实现为 Python 类的包装器。

tkinter 的主要优点是速度快,而且通常与 Python 捆绑在一起。 虽然它的标准文档很薄弱,但有很好的材料可用,其中包括:参考资料、教程、一本书等。 tkinter 也以过时的外观和感觉而闻名,这在 Tk 8.5 中得到了极大的改进。 不过,您可能会对许多其他 GUI 库感兴趣。 Python wiki 列出了几个替代的 GUI 框架和工具