如何更改tkinter应用程序的整体主题? [英] How do I change the overall theme of a tkinter application?

查看:611
本文介绍了如何更改tkinter应用程序的整体主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将tkinter应用程序的主题更改为蛤.

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')

推荐答案

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

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

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

与主题相关的许多操作要求您具有 可用ttk.Style()类的实例(在Python的意义上 班级).例如,要获取您中可用主题的列表 安装:

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')

.theme_names()方法返回一个元组,其中包含 可用样式. "classic"主题为您提供了原始的,ttk之前的版本 外观.

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

要确定默认情况下获得的主题,请使用.theme_use() 没有参数的方法.要更改当前主题,请使用相同的名称 所需主题名称作为参数的方法:

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应用程序的整体主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆