Skip to content
Advertisement

How to change whole app’s theme when used within Class, Tkinter, ttkThemes, ThemedTk Python

Summary: I searched the internet about additional themes for tkinter. I found ttkthemes – ThemedTk option. However, my app is created within class. The difference between the example shown in the module website, the themedtk example is applied with root method. Here is the code:

JavaScript

When I run the application and the click the style and choose a style. I receive this error:

AttributeError: ‘_tkinter.tkapp’ object has no attribute ‘_toplevel’

It took so much time of me to solve it. Thanks in advance.

Advertisement

Answer

You forgot () in line

JavaScript

and later you have to remove self in

JavaScript

and now it runs without error but still it doesn’t change theme.

Maybe it needs to use widgets from ttk.


EDIT:

You have to use ThemedTk in place of tk.Tk. And use directly self.set_theme()

And of course you need some widgets from ttk.

JavaScript

enter image description here

Or you can use Tk with ThemedStyle (instead of ThemedTk)
and then you can set self.style = ThemedStyle()
but you have to use self.style.theme_use(name) instead of self.set_theme(name)

And it needs self.style.get_themes() instead of self.get_themes().

JavaScript

I found screenshots for all themes: List of ttk Themes


OLD ANSWER

I have only working example with ttk.Buttons

JavaScript

Default:

enter image description here

Blue:

enter image description here

Kroc:

enter image description here

Radiance or Ubuntu:

enter image description here

Winxpblue:

enter image description here


Source keep on GitHub: furas / python-examples / tkinter / themes-change-ttkthemes / buttons

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement