Ole*_*pin 54 tkinter ttk python-3.x
我在哪里可以找到最现代化的教程,教tkinter一起ttk?
Tkinter 似乎是Python 3的唯一方法(不建议使用Python 2),并且ttk给了我好看的GUI的希望.
Tod*_*odd 52
我发现TkDocs教程非常有用.它描述了Tk使用Python和构建接口Tkinter,ttk并且记录了Python 2和3之间的差异.它还有Perl,Ruby和Tcl中的示例,因为目标是教授Tk本身,而不是特定语言的绑定.
我从头到尾都没有经历过整个事情,而是只使用了许多主题作为我坚持的事情的例子,但它非常具有教学性和舒适性.今天阅读介绍和前几节让我觉得我将开始研究其余部分.
最后,它是最新的,该网站有一个非常漂亮的外观.他还有一些其他页面值得一试(Widgets,Resources,Blog).这家伙做了很多事情,不仅教授Tk,还提高了人们的理解,认为它不是曾经的丑陋野兽.
Hon*_*Abe 20
某些示例中使用的模块名称是Python 2.7中使用的模块名称.
这是Python 3中名称更改的参考:link
ttk的一个便利是你可以选择一个先前存在的 主题,
这是应用于ttk小部件的全套样式.
这是我写的一个例子(对于Python 3),它允许您从Combobox中选择任何可用的主题:
import random
import tkinter
from tkinter import ttk
from tkinter import messagebox
class App(object):
def __init__(self):
self.root = tkinter.Tk()
self.style = ttk.Style()
available_themes = self.style.theme_names()
random_theme = random.choice(available_themes)
self.style.theme_use(random_theme)
self.root.title(random_theme)
frm = ttk.Frame(self.root)
frm.pack(expand=True, fill='both')
# create a Combobox with themes to choose from
self.combo = ttk.Combobox(frm, values=available_themes)
self.combo.pack(padx=32, pady=8)
# make the Enter key change the style
self.combo.bind('<Return>', self.change_style)
# make a Button to change the style
button = ttk.Button(frm, text='OK')
button['command'] = self.change_style
button.pack(pady=8)
def change_style(self, event=None):
"""set the Style to the content of the Combobox"""
content = self.combo.get()
try:
self.style.theme_use(content)
except tkinter.TclError as err:
messagebox.showerror('Error', err)
else:
self.root.title(content)
app = App()
app.root.mainloop()
Run Code Online (Sandbox Code Playgroud)
旁注:我注意到使用Python 3.3时有一个'vista'主题(但不是2.7).