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

前端 未结 3 1191
执念已碎
执念已碎 2020-12-20 21:26

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 tkint         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 21:56

    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!

提交回复
热议问题