Tkinter ttk 查看自定义主题设置

2024-02-06

使用后ttk.Style().theme_create('name', settings={})可以看到该主题的设置吗?

我问的原因是当我创建一个新主题并添加ttk.Notebook(root)对于我的代码,选项卡有圆角,这是我不想要的。

这是一个例子:

import tkinter as tk
import tkinter.ttk as ttk


root = tk.Tk()
root.title("Tab Example")
root.geometry('270x270')

background = '#ffffff'
background_dark = '#f2f2f2'

style = ttk.Style()
style.theme_create('white', settings={
    'TLabel': {'configure': {'background': background}},
    'TFrame': {'configure': {'background': background}},
    'TNotebook': {
        'configure': {'background': background_dark, 'tabmargins': [0, 7, 2, 0], 'padding': [7, 2]}},
    'TNotebook.Tab': {
        'configure': {'background': background_dark, 'padding': [7, 2], 'focuscolor': 'clear'},
        'map': {'background': [('selected', background)]}}})

style.theme_use('white')

tab = ttk.Notebook(root)

tab1 = ttk.Frame(tab)
tab2 = ttk.Frame(tab)

tab.add(tab1, text='Tab 1')
tab.add(tab2, text='Tab 2')
tab.pack(expand=1, fill="both")

ttk.Label(tab1, text="example").pack(padx=36, pady=36)
ttk.Label(tab2, text="example 2").pack(padx=36, pady=36)

root.mainloop()

如果您删除style.theme_create() / style.theme_use()那么选项卡不再有圆角,因此程序必须默认添加该样式。

如果没有办法查看主题设置(似乎无法在docs https://docs.python.org/3/library/tkinter.ttk.html#ttk-styling)是否有我可以使用的可能设置列表?专门针对选项卡边框的东西?

就这一点而言,有一个类似的问题,有 Tkinter/ttk 风格参考吗? https://stackoverflow.com/questions/24592132/is-there-a-tkinter-ttk-style-reference但是,提供的答案中的第一个链接没有列出以下边框角或边框样式的任何内容ttk::笔记本 http://tmml.sourceforge.net/doc/tk/ttk_notebook.html而第二个链接没有响应。

EDIT

扩展Atlas435的答案,

style_name = ttk.Notebook(None).winfo_class()
# print(style_name) -> 'TNotebook'

print(style.layout('TNotebook')) # -> [('Notebook.client', {'sticky': 'nswe'})]
print(style.element_options('Notebook.client')) # -> ('borderwidth', 'background')

除了'background',我无法看到上面使用的自定义设置的名称'TNotebook':

style.theme_create('white', settings={
    'TNotebook': {'configure':
        {'background': background_dark, 'tabmargins': [0, 7, 2, 0], 'padding': [7, 2]}}})

如果我这样做,我会更接近我正在寻找的东西,但仍然不完全是:

print(style.layout('Tab')) # -> [('Notebook.tab', {'sticky': 'nswe', 'children': [('Notebook.padding', {'sticky': 'nswe', 'children': [('Notebook.label', {'sticky': 'nswe'})]})]})]
print(style.element_options('Notebook.tab')) # -> ('borderwidth', 'background')

骑自行车穿过另一个element_options (Notebook.padding and Notebook.label)也不提供我正在寻找的值:(

EDIT 2

一些样式选项没有在任何地方列出,包括Tcl/Tk 文档 https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_notebook.htm#M38.

一个例子是'focuscolor' for 'TNotebook.Tab'当选项卡处于焦点时,它会更改选项卡周围虚线的颜色。

另一个例子是当使用ttk.Style().theme_use('default') or .theme_use('classic'),笔记本中的选项卡具有圆角边缘。如果你使用.theme_use('clam') or .theme_use('vista'),笔记本中的选项卡没有圆角边缘。

我无法在任何文档中找到该样式选项,并且无法通过程序打印它(见上文)Edit部分)。

现在我接受当前的最佳答案(Atlas435)来帮助我得出这个结论。

对于其他遇到此问题的人来说,一个临时解决方案可能是设置'clam' or 'vista' as a parent使用时ttk.Style().theme_create()或者创建一个看起来像选项卡的图片,并具有您想要和使用的样式tab.add(tab1, image=img)

FINAL

提供完整列表,请查看 Atlas 435answer https://stackoverflow.com/questions/65461962/tkinter-ttk-see-custom-theme-settings/65464537#65464537


ttk 提供的所有选项的官方列表

终于找到了一个列表,其中包含使用 ttk 进行样式设置的所有颜色选项。https://wiki.tcl-lang.org/page/Changing+Widget+Colors https://wiki.tcl-lang.org/page/Changing+Widget+Colors


ttk.Button

ttk::style configure TButton -background color
ttk::style configure TButton -foreground color
ttk::style configure TButton -font namedfont
ttk::style configure TButton -focuscolor color
ttk::style map TButton -background \
    [list active color disabled color readonly color]
ttk::style map TButton -foreground \
    [list active color disabled color readonly color]

ttk::style configure TButton -bordercolor color
ttk::style configure TButton -lightcolor color
ttk::style configure TButton -darkcolor color

ttk.Checkbutton

ttk::style configure TCheckbutton -background color
ttk::style configure TCheckbutton -foreground color
ttk::style configure TCheckbutton -font namedfont
ttk::style map TCheckbutton -background \
    [list active color disabled color readonly color]
ttk::style map TCheckbutton -foreground \
    [list active color disabled color readonly color]
ttk::style configure TCheckbutton -indicatorcolor color
ttk::style map TCheckbutton -indicatorcolor \
    [list selected color pressed color]
ttk::style configure TCheckbutton -indicatorrelief relief
ttk::style configure TCheckbutton -indicatormargin padding
ttk::style configure TCheckbutton -indicatordiameter size
ttk::style configure TCheckbutton -borderwidth size
ttk::style configure TCheckbutton -focuscolor color

ttk.Combobox

ttk::style configure TCombobox -background color
ttk::style configure TCombobox -foreground color
ttk::style configure TCombobox -fieldbackground color
ttk::style configure TCombobox -darkcolor color
ttk::style configure TCombobox -lightcolor color
ttk::style configure TCombobox -selectbackground color
ttk::style configure TCombobox -selectforeground color
ttk::style configure TCombobox -bordercolor color
ttk::style configure TCombobox -insertcolor color
ttk::style configure TCombobox -insertwidth color
ttk::style configure TCombobox -arrowsize size
ttk::style configure TCombobox -arrowcolor color
ttk::style map TCombobox -background \
    [list disabled color readonly color]
ttk::style map TCombobox -foreground \
    [list disabled color readonly color]
ttk::style map TCombobox -fieldbackground \
    [list disabled color readonly color]
option add *TCombobox*Listbox.background color
option add *TCombobox*Listbox.foreground color
option add *TCombobox*Listbox.selectBackground color
option add *TCombobox*Listbox.selectForeground color

ttk.条目

ttk::style configure TEntry -background color
ttk::style configure TEntry -foreground color
ttk::style configure TEntry -fieldbackground color
ttk::style configure TEntry -selectbackground color
ttk::style configure TEntry -selectforeground color
ttk::style configure TEntry -bordercolor color
ttk::style configure TEntry -lightcolor color
ttk::style configure TEntry -insertcolor color
ttk::style configure TEntry -insertwidth color
ttk::style map TEntry -background \
    [list disabled color readonly color]
ttk::style map TEntry -foreground \
    [list disabled color readonly color]
ttk::style map TEntry -fieldbackground \
    [list disabled color readonly color]
.entry configure -font namedfont

ttk.Labelframe

ttk::style configure TLabelframe -background color
ttk::style configure TLabelframe -bordercolor color
ttk::style configure TLabelframe -lightcolor color
ttk::style configure TLabelframe -darkcolor color
ttk::style configure TLabelframe.Label -background color
ttk::style configure TLabelframe.Label -foreground color
ttk::style configure TLabelframe.Label -font namedfont

ttk.列表框

.listbox configure -background color
.listbox configure -foreground color
.listbox configure -disabledforeground color
.listbox configure -selectbackground color
.listbox configure -selectforeground color
.listbox configure -font namedfont
.listbox configure -borderwidth size
.listbox configure -relief relief
.listbox configure -highlightthickness size
.listbox configure -highlightcolor color
.listbox configure -highlightbackground color

menu

.menu configure -background color
.menu configure -foreground color
.menu configure -activebackground color
.menu configure -activeforeground color
.menu configure -disabledforeground color
.menu configure -font namedfont
.menu configure -selectcolor color
.menu configure -activeborderwidth size
.menu configure -relief relief

ttk.菜单按钮

ttk::style configure TMenubutton -background color
ttk::style configure TMenubutton -foreground color
ttk::style configure TMenubutton -font namedfont
ttk::style configure TMenubutton -arrowcolor color
ttk::style map TMenubutton -background \
    [list active color disabled color]
ttk::style map TMenubutton -foreground \
    [list active color disabled color]
ttk::style map TMenubutton -arrowcolor \
    [list active color disabled color]

ttk笔记本

ttk::style configure TNotebook -background color
ttk::style configure TNotebook -bordercolor color
ttk::style configure TNotebook -darkcolor color
ttk::style configure TNotebook -lightcolor color
ttk::style configure TNotebook.Tab -background color
ttk::style configure TNotebook.Tab -foreground color
ttk::style configure TNotebook.Tab -bordercolor color
ttk::style configure TNotebook -focuscolor color
ttk::style configure TNotebook -focusthickness size

ttk::style configure TNotebook.Tab -focuscolor color
ttk::style map TNotebook.Tab -background \
    [list selected color active color disabled color]
ttk::style map TNotebook.Tab -foreground \
    [list selected color active color disabled color]
ttk::style map TNotebook.Tab -lightcolor \
    [list selected color {} color]
ttk::style configure TNotebook.Tab -font namedfont
ttk::style map TNotebook.Tab -font \
    [list selected namedfont active namedfont disabled namedfont]

ttk.Panedwindow

ttk::style configure TPanedwindow -background color

ttk::style configure Sash -sashthickness 5
ttk::style configure Sash -sashrelief relief
ttk::style configure Sash -sashpad 2
ttk::style configure Sash -handlesize 5
ttk::style configure Sash -handlepad 5

ttk::style configure Sash -background color
ttk::style configure Sash -lightcolor color
ttk::style configure Sash -bordercolor color

ttk.进度条

ttk::style configure TProgressbar -background color
ttk::style configure TProgressbar -troughcolor color
ttk::style configure TProgressbar -lightcolor color
ttk::style configure TProgressbar -darkcolor color
ttk::style configure TProgressbar -bordercolor color
ttk::style configure TProgressbar -barsize size
ttk::style configure TProgressbar -pbarrelief relief
ttk::style configure TProgressbar -borderwidth size

ttk.单选按钮

ttk::style configure TRadiobutton -background color
ttk::style configure TRadiobutton -foreground color
ttk::style configure TRadiobutton -font namedfont
ttk::style map TRadiobutton -background \
    [list active color disabled color readonly color]
ttk::style map TRadiobutton -foreground \
    [list active color disabled color readonly color]
ttk::style configure TRadiobutton -indicatorcolor color
ttk::style map TRadiobutton -indicatorcolor \
    [list selected color pressed color]

ttk.量表

ttk::style configure TScale -background color

ttk::style configure TScale -troughcolor color
ttk::style map TScale -background \
    [list active color]
ttk::style configure TScale -troughrelief relief

ttk::style configure TScale -sliderrelief relief
ttk::style configure TScale -sliderlength size
ttk::style configure TScale -sliderthickness size

ttk::style configure TScale -lightcolor color
ttk::style configure TScale -darkcolor color
ttk::style configure TScale -bordercolor color

ttk.滚动条

ttk::style configure TScrollbar -background color
ttk::style configure TScrollbar -troughcolor color
ttk::style configure TScrollbar -arrowcolor color
ttk::style configure TScrollbar -bordercolor color
ttk::style configure TScrollbar -darkcolor color
ttk::style configure TScrollbar -lightcolor color
ttk::style configure TScrollbar -sliderrelief relief
ttk::style map TScrollbar -background \
    [list active color disabled color]
ttk::style map TScrollbar -foreground \
    [list active color disabled color]
ttk::style map TScrollbar -arrowcolor \
    [list disabled color]

ttk.分隔符

ttk::style configure TSeparator -background color

ttk.Sizegrip

ttk::style configure TSizegrip -background color

ttk.Spinbox

ttk::style configure TSpinbox -background color
ttk::style configure TSpinbox -foreground color
ttk::style configure TSpinbox -darkcolor color
ttk::style configure TSpinbox -lightcolor color
ttk::style configure TSpinbox -fieldbackground color
ttk::style configure TSpinbox -selectbackground color
ttk::style configure TSpinbox -selectforeground color
ttk::style configure TSpinbox -arrowsize size
ttk::style configure TSpinbox -arrowcolor color
ttk::style configure TSpinbox -bordercolor color
ttk::style configure TSpinbox -insertcolor color
ttk::style configure TSpinbox -insertwidth color
ttk::style map TSpinbox -background \
    [list active color disabled color readonly color]
ttk::style map TSpinbox -foreground \
    [list active color disabled color readonly color]
ttk::style map TSpinbox -fieldbackground \
    [list active color disabled color readonly color]
ttk::style map TScrollbar -arrowcolor \
    [list disabled color]
.spinbox configure -font namedfont

ttk.Text

.text configure -background color
.text configure -foreground color
.text configure -selectforeground color
.text configure -selectbackground color
.text configure -inactiveselectbackground color
.text configure -insertbackground color
.text configure -font namedfont
.text configure -relief relief
.text configure -borderwidth size
.text configure -highlightcolor color
.text configure -highlightthickness size
.text configure -highlightbackground color

ttk.Treeview

ttk::style configure Treeview -background color
ttk::style configure Treeview -foreground color
ttk::style configure Treeview -font namedfont
ttk::style configure Treeview -fieldbackground color
ttk::style map Treeview -background \
    [list selected color]
ttk::style map Treeview -foreground \
    [list selected color]
ttk::style configure Treeview -rowheight [expr {[font metrics namedfont -linespace] + 2}]
ttk::style configure Heading -font namedfont
ttk::style configure Heading -background color
ttk::style configure Heading -foreground color
ttk::style configure Heading -padding padding
ttk::style configure Item -foreground color 
ttk::style configure Item -focuscolor color
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Tkinter ttk 查看自定义主题设置 的相关文章

随机推荐

  • Rserve 服务器:如何终止阻塞实例(评估永远)?

    我需要执行Reval以多线程的方式 这是Rserve提供得相当好 但是 如果一个实例的评估时间太长 我需要能够关闭正在计算阻塞评估的实例 据我测试 给定的实例将拒绝关闭 直到评估完成 显然 它需要在再次监听之前获取结果 所以这是我的问题 有
  • 如何使用 API 从 Google 文档中提取标题

    目前正在尝试创建一个 python 脚本来检查 google 文档的各种 SEO 页面指标 谷歌文档 API 有一个好样本 https developers google com docs api samples extract text展
  • #如果忽略 DEBUG(VB.net 或 C#)

    我的代码中有几个到目前为止运行良好的代码 If DEBUG Then some code here End If 现在 我注意到 最近 If DEBUG then End If 中的代码 也在 释放模式 下执行 这很奇怪 以前没有发生过 可
  • 显示轨迹指示器

    从图像中您可以看到 在左侧发射的球在其后面发射 与计算的轨迹不符 我使用 SO 中的方程绘制球轨迹question https stackoverflow com questions 10401644 mousejointdef libgd
  • 由于 Windows Vista Home Premium 版本缺少 Windows 身份验证 IIS 组件...有修复吗?

    显然 Windows Vista Home Basic 和 Premium 都没有附带 IIS 的集成 Windows 身份验证 您需要商业版 所以有人知道如何为 IIS 安装 Windows 身份验证吗 我进入程序和功能 gt 打开或关闭
  • 如何使用脆皮形式格式化 django-filters?

    是否可以使用 django crispy forms 格式化 django filters 过滤器表单 我一直在尝试这样做 但是django filters FilterSet似乎不接受脆脆的表单格式 来自 DeviceFilter 类 它
  • jol GraphLayout 输出中的“(其他内容)”是什么?

    当使用 jol 的 GraphLayout 类打印从对象实例引用的对象图时 某些输出条目显示 其他内容 而不是类型和引用路径 例如 考虑以下代码 该代码打印 20 个随机 Integer 对象列表的图形 List
  • 如何与我的适配器类中的片段进行通信

    我创建了一个自定义适配器类 在该类中 当我单击列表视图布局时 我有一个代码必须向我的片段发送消息 谷歌搜索后 最好的方法可能是使用界面 其中大部分都是activity与fragment之间进行通信的例子 但就我而言 我对如何在适配器类与片段
  • 将 C Struct 编组为 C# 委托的返回值

    我试图从绑定到本机函数的委托中按值返回一个小 8 字节 结构 但在针对 NET Framework 2 0 时遇到以下错误 在针对 4 0 时 代码似乎可以正常工作 testclient exe 中发生类型为 System AccessVi
  • 传递格式化的 NSDate

    我传递给实例方法的格式化日期未保存 打印正确的日期 有人可以帮忙吗 调用方法代码片段 NSDateFormatter dateFormatter NSDateFormatter alloc init autorelease dateForm
  • 卡在 PHP 查询上

    我创建了一个页面 允许用户更改密码和电子邮件 所有这些都有效 但由于某种原因 当我只想更改我的电子邮件时 我也得到了该字段当前密码不正确 电子邮件本身在数据库中发生了变化 但这显示了出来 我显然已经验证了它的显示 但我不确定如何编写一个新查
  • 如何让它更短(Pythonic)?

    我必须检查很多世界是否在字符串中 代码如下所示 if string 1 in var string or string 2 in var string or string 3 in var string or string n in var
  • 具有本机扩展的 Ruby gem 无法在 AWS Lambda 上运行

    我有一个 ruby 脚本 正在尝试在 AWS Lambda 上运行 我如何让它使用带有本机扩展的 Ruby gem 我已经通过安装了我的 Ruby gemsbundle install deployment并将它们包含在我的部署中 当我在
  • C# 更改系统区域设置

    需要将系统区域设置更改为不同的国家 地区 我尝试过 SystemParametersInfo GetKeyboardLayout 但没有帮助 如何更改控制台应用程序的 C 系统区域设置 e g Thread CurrentThread Cu
  • 更改大表中的mysql字段名称

    我有一个包含 2100 万行的表 我必须更改其中一个行名称 当我尝试使用查询 alter table company change id new id int 11 时 查询永远不会结束 有没有简单的方法来更改大mysql表字段名称 首先
  • Excel:查找数组中的最后一个值

    我有一个数据集 gt A b c d AA BB gt 1 2 3 4 gt apple apple apple gt orange pear pear apple pear gt grapefruit grape grape grape
  • Eclipse 在 Ubuntu 14.04 中无法启动

    我尝试在 Ubuntu 14 04 中启动 Eclipse 时遇到问题 启动图片弹出 然后闪烁 变成白色 直到王国来临之前什么也没有发生 我尝试过 Luna Kepler 和 3 8 来自 Ubuntu 存储库 EE 和 SE 版本 两者相
  • Service Worker 可以缓存 POST 请求吗?

    我尝试在 fetch 事件的服务工作人员中缓存 POST 请求 I used cache put event request response 但返回的承诺被拒绝TypeError Invalid request method POST 当
  • 如何在打印语句中使用零填充标志精确打印两个位置

    如果想使用零垫进行此方法打印 你该怎么做 int month day public void printNumeric System out printf month day n i would like the month if it i
  • Tkinter ttk 查看自定义主题设置

    使用后ttk Style theme create name settings 可以看到该主题的设置吗 我问的原因是当我创建一个新主题并添加ttk Notebook root 对于我的代码 选项卡有圆角 这是我不想要的 这是一个例子 imp