Python 中 tkinter 和 tkinter.ttk 的小部件有什么区别? [英] What is the difference between the widgets of tkinter and tkinter.ttk in Python?
问题描述
Python 3 中的主要 tkinter
模块及其子模块 ttk
似乎包含相同的小部件(即 Buttons
、CheckButtons代码>等).
The main tkinter
module and its submodule ttk
in Python 3 appear to contain identical widgets (i.e. Buttons
, CheckButtons
, etc.).
因此,在创建按钮时,可以自由使用 tkinter.Button
小部件或 tkinter.ttk.Button
.
So, when creating a button, one has the freedom to either use a tkinter.Button
widget or a tkinter.ttk.Button
.
你知道它们有什么区别吗?为什么你会选择其中之一?
Do you know what is the difference between them? Why would you choose one or the other?
推荐答案
tkinter
中的小部件高度且易于配置.您几乎可以完全控制它们的外观 - 边框宽度、字体、图像、颜色等.
The widgets in tkinter
are highly and easily configurable. You have almost complete control over how they look - border widths, fonts, images, colors, etc.
ttk
小部件使用样式来定义它们的外观,因此如果您想要一个非标准按钮,则需要做更多的工作.ttk
小部件也有一些文档不足.理解底层的主题和布局引擎(小部件本身的布局,而不是 pack
、grid
和 place
)是一个挑战.
ttk
widgets use styles to define how they look, so it takes a bit more work if you want a non-standard button. ttk
widgets are also a little under-documented. Understanding the underlying theme and layout engines (layout within the widgets themselves, not pack
, grid
and place
) is a challenge.
一般来说,主题小部件会给你一个看起来更原生"的应用程序,但代价是失去了可配置性.
Generally speaking, the themed widgets will give you an application that looks more "native", but at the expense of a loss of configurability.
我的建议是,如果您希望 GUI 看起来更现代一点,请使用 ttk
小部件,如果您需要更多的可配置性,则使用 tkinter 小部件.您可以在同一个应用程序中同时使用它们.
My advice is to use ttk
widgets if you want your GUI to look a little more modern, and the tkinter widgets if you need a bit more configurability. You can use them both in the same applications.
这篇关于Python 中 tkinter 和 tkinter.ttk 的小部件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!