Ttk带有18个小部件,其中12个已经存在于tkinter中: Button
, Checkbutton
, Entry
, Frame
, Label
, LabelFrame
, Menubutton
, PanedWindow
, Radiobutton
, Scale
, Scrollbar
和 Spinbox
。其他六个是新的: Combobox
, Notebook
, Progressbar
, Separator
, Sizegrip
和Treeview
。它们都是 Widget
的子类。
使用Ttk小部件可以改善应用程序的外观和感觉。如上所述,样式的编码方式存在差异。
Tk的代码:
l1 = tkinter.Label(text="Test", fg="black", bg="white")
l2 = tkinter.Label(text="Test", fg="black", bg="white")
Ttk的代码:
style = ttk.Style()
style.configure("BW.TLabel", foreground="black", background="white")
l1 = ttk.Label(text="Test", style="BW.TLabel")
l2 = ttk.Label(text="Test", style="BW.TLabel")
有关TtkStyling的更多信息,请参见Style
类文档。