我知道 Tkinter 不是那么现代,不是那么酷,使用 PyQt 等可能更好。
但对我来说有趣的是 Tkinter 在 Ubuntu (Linux) 中看起来不是那么丑。看起来 python 的 Tkinter 的 brew 版本(在 OS X 中)是用内置主题编译的,看起来不错:
但是 Ubuntu 的 Tkinter 让我哭了:
我已经读过,为了获得好的主题,我需要使用 ttk,但我不知道具体如何。我的代码如下所示:
from Tkinter import *
class App():
def __init__(self, master):
frame = Frame(master)
frame.pack()
master.title("Just my example")
self.label = Label(frame, text="Type very long text:")
self.entry = Entry(frame)
self.button = Button(frame,
text="Quit", fg="red", width=20,
command=frame.quit)
self.slogan = Button(frame,
text="Hello", width=20,
command=self.write_slogan)
self.label.grid(row=0, column=0)
self.entry.grid(row=0, column=1)
self.slogan.grid(row=1, column=0)
self.button.grid(row=1, column=1)
def write_slogan(self):
print "Tkinter is easy to use!"
root = Tk()
app = App(root)
root.mainloop()
如何应用标准的 ubuntu 主题或至少更好的主题?
谢谢。
原文由 ipeacocks 发布,翻译遵循 CC BY-SA 4.0 许可协议
可以使用以下命令查看 ttk 的所有可用主题:
因此,您可以在您的 Tkinter 版本中使用“clam”、“alt”、“default”、“classic”主题。
在尝试了所有这些之后,我认为最好的是“蛤蜊”。您可以通过以下方式使用这个或任何其他方式:
结果:
OS X 使用预编译主题“aqua”,因此小部件看起来更好。
此外,Ttk 小部件不支持纯 Tkinter 支持的所有选项。