How do I change the overall theme of a tkinter application?
Asked Answered
A

3

11

I want to change the theme of my tkinter application to clam.

What is the code and where do I put it? I have tried:

from tkinter import *
from tkinter.ttk import *
s=ttk.Style()
s.theme_use('clam')
Appalachia answered 23/6, 2014 at 13:50 Comment(2)
Use tkinter.ttk to get the the themed version of Tk.Bastian
thanks, how do i change to clam, default, ect.Appalachia
R
15

To change the theme, call .theme_use() with the theme's name as the argument.

From https://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-theme-layer.html

A number of operations related to themes require that you have available an instance of the ttk.Style() class (in the Python sense of class). For example, to obtain a list of the available themes in your installation:

>>> import ttk  # import tkinter.ttk as ttk for Python 3
>>> s=ttk.Style()
>>> s.theme_names()
('clam', 'alt', 'default', 'classic')

The .theme_names() method returns a tuple containing the names of the available styles. The 'classic' theme gives you the original, pre-ttk appearance.

To determine which theme you get by default, use the .theme_use() method with no arguments. To change the current theme, call this same method with the desired theme name as the argument:

>>> s.theme_use()
'default'
>>> s.theme_use('alt')
>>> s.theme_use()
'alt'
Rothwell answered 23/6, 2014 at 15:19 Comment(2)
ImportError: No module named 'ttk'.Appalachia
Sorry, Python 3: import tkinter.ttk as ttkRothwell
T
4

This post is pretty outdated, here is how you can easily set the theme in Python3 with just one line of code:

Add this below your "Tk()" line. For example:

window = Tk() # <--- Main window line

ttk.Style().theme_use('default') # <--- Change default to whichever theme you want to use.

Where 'default' is the name of the default theme. Change 'default' to any of the available themes that you like.

Here is a good list of themes with screenshots:

<-- Current themes as of 2020 -->

https://ttkthemes.readthedocs.io/en/latest/themes.html

Some themes from the list above are not included in the main tkinter download.

If this is the case, you can easily install the theme files that aren't included in the default ttk install by running this command:

python3 -m pip install git+https://github.com/RedFantom/ttkthemes

Hope this helped you!

Tompion answered 21/8, 2020 at 3:43 Comment(1)
ttk.Style().theme_use('default') cannot be used with ttkthemes themes? please tell how to use it with ttkthemesRambling
U
3
>>> from tkinter import ttk

>>> s=ttk.Style()

>>> s.theme_names() """======== if you are under win 8.1 you must see ..
 ('winnative', 'clam', 'alt', 'default', 'classic', 'vista', 'xpnative') you can use for example 'clam' ===== """

>>> s.theme_use('clam')
Unbolt answered 19/8, 2016 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.