gpt4 book ai didi

tkinter - 如何更改 tkinter 应用程序的整体主题?

转载 作者:行者123 更新时间:2023-12-01 08:58:23 26 4
gpt4 key购买 nike

我想将我的 tkinter 应用程序的主题更改为 clam。

代码是什么,我把它放在哪里?我试过了:

from tkinter import *
from tkinter.ttk import *
s=ttk.Style()
s.theme_use('clam')

最佳答案

要更改主题,请调用 .theme_use()以主题的名称作为参数。

来自 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'

关于tkinter - 如何更改 tkinter 应用程序的整体主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24367710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com