简体   繁体   中英

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. However, after importing and using ttkthemes, it seems that it only affects ttk widgets and not the normal tk ones. Is there a way to convert the tk widgets into 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?

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.

... it seems that it only affects ttk widgets and not the normal tk ones. Is there a way to convert the tk widgets into ttk.

No, there is not. Tk widgets and ttk widgets are separate things. As you've discovered, the ttk styles only affect ttk widgets.

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?

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. However, the widgets are sufficiently different that rewriting is the best way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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