更改ttk笔记本的文本大小和颜色

问题描述 投票:0回答:1

我创建了一个窗口,并使用ttk笔记本查看选项卡菜单。我无法更改标签菜单的文本大小和字体,背景颜色等。

from tkinter import *
from tkinter import ttk
import tkinter

window = Tk()
style = ttk.Style()
note = ttk.Notebook(window)

window.tab1 = ttk.Frame(note)
window.tab2 = ttk.Frame(note)
window.tab3 = ttk.Frame(note)
window.tab4 = ttk.Frame(note)

note.add(window.tab1, text = "Home ")
note.add(window.tab2, text = "Disconnected ")
note.add(window.tab3, text = "Alarm ")
note.add(window.tab4, text = "")

note.pack()
style.configure('TNotebook.Tab', foreground='red')
window.mainloop()

我如何分别更改“ home”,“ Alarm”等文字的大小和颜色? style.configure('TNotebook.Tab',前景色='红色')更改笔记本的正面颜色,所有选项卡文本颜色均被更改。我应该如何更改假定“已断开连接”的文本的颜色?

python jupyter-notebook ttk
1个回答
0
投票

这是我找到的代码,我当然对其进行了编辑,但是它可能会帮助您解决一些需求,例如颜色,(仍然不清楚文本是否可以帮助您:)]

style = ttk.Style()
style.theme_create('Cloud', settings={
    ".": {
        "configure": {
            "background": '#aeb0ce', # All colors except for active tab-button
            "font": 'red'
        }
    },
    "TNotebook": {
        "configure": {
            "background":'black', # color behind the notebook
            "tabmargins": [5, 5, 0, 0], # [left margin, upper margin, right margin, margin beetwen tab and frames]
        }
    },
    "TNotebook.Tab": {
        "configure": {
            "background": 'dark blue', # Color of non selected tab-button
            "padding": [5, 2], # [space beetwen text and horizontal tab-button border, space between text and vertical tab_button border]
            "font":"white"
        },
        "map": {
            "background": [("selected", '#aeb0ce')], # Color of active tab
            "expand": [("selected", [1, 1, 1, 0])] # [expanse of text]
        }
    }
})
style.theme_use('Cloud')
© www.soinside.com 2019 - 2024. All rights reserved.