简体   繁体   English

将 Tkinter 转换为 ttk

[英]Converting Tkinter to ttk

I've been using tkinter in order to code an application, but I've recently learned that there is a more modern ttk which I may use to style and theme widgets.我一直在使用 tkinter 来编写应用程序,但我最近了解到有一个更现代的 ttk 可以用来设置样式和主题小部件。 However, after importing and using ttkthemes, it seems that it only affects ttk widgets and not the normal tk ones.但是,在导入和使用 ttkthemes 之后,它似乎只影响 ttk 小部件,而不影响普通的 tk 小部件。 Is there a way to convert the tk widgets into ttk.有没有办法将 tk 小部件转换为 ttk. My current imports are我目前的进口是

from tkinter import *
from tkinter import ttk
from ttkthemes import ThemedTk

I guess I can just rewrite the tk portion that I have to be ttk widgets, but is there a simpler way to go about this?我想我可以重写我必须是 ttk 小部件的 tk 部分,但是有没有更简单的方法来 go 关于这个?

Try this:尝试这个:

from tkinter.ttk import *

The name of the widgets are the same and there are some other cool widgets like Combobox, Treeview, etc.小部件的名称相同,还有一些其他很酷的小部件,如 Combobox、Treeview 等。

... it seems that it only affects ttk widgets and not the normal tk ones. ...似乎它只影响 ttk 小部件,而不影响普通的 tk 小部件。 Is there a way to convert the tk widgets into ttk.有没有办法将 tk 小部件转换为 ttk.

No, there is not.不,那里没有。 Tk widgets and ttk widgets are separate things. Tk 小部件和 ttk 小部件是不同的东西。 As you've discovered, the ttk styles only affect ttk widgets.正如您所发现的,ttk styles 仅影响 ttk 小部件。

I guess I can just rewrite the tk portion that I have to be ttk widgets, but is there a simpler way to go about this?我想我可以重写我必须是 ttk 小部件的 tk 部分,但是有没有更简单的方法来 go 关于这个?

Not really.并不真地。 Since you're doing a wildcard import of tkinter, you can do a wildcard import of ttk too, and the ttk widget classes will overwride the tkitner classes.由于您正在执行 tkinter 的通配符导入,因此您也可以执行 ttk 的通配符导入,并且 ttk 小部件类将覆盖 tkitner 类。 However, the widgets are sufficiently different that rewriting is the best way.但是,这些小部件有很大的不同,因此重写是最好的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM