Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

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')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...