Change tab title color in ttk.Notebook

Gretings!

I want to change the color displayed in the tab title created with ttk.Notebook. After searching for a while, I found that we can use ttk to change the style of ttk widgets. Styling, because laptops apparently don't have configuration options for changing its colors. However, I only found how to change the background and foreground of the NoteBook object, but not how to adjust the tab title, whose background is either white (if selected) or gray (if not selected).

Can anybody help me?

This is the code that I have now related to what I'm trying to do

import Tkinter as tki
import ttk

...
##Other code. Not relevant here
...

#create tabs and associate the apropriate frames to it
tabs = ttk.Notebook(parent.master)
ttk.Style().configure("TNotebook", background=mainWcolor, foreground='green')   #configure "tabs" background color

paramsFrame = tki.Frame(tabs, bg=mainWcolor)   #frame with control parameters
comsFrame = tki.Frame(tabs, bg=mainWcolor)     #frame with communication parameters.
ssInfoFrame = tki.Frame(tabs, bg=mainWcolor)   #frame with start and stop messages and procedures

tabs.add(paramsFrame, text = "Control")
tabs.add(comsFrame, text = "Communications")
tabs.add(ssInfoFrame, text = "Start & Stop info")
tabs.pack()

Thanks in advance.

+4
source share
2

.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

mygreen = "#d2ffd2"
myred = "#dd0202"

style = ttk.Style()

style.theme_create( "yummy", parent="alt", settings={
        "TNotebook": {"configure": {"tabmargins": [2, 5, 2, 0] } },
        "TNotebook.Tab": {
            "configure": {"padding": [5, 1], "background": mygreen },
            "map":       {"background": [("selected", myred)],
                          "expand": [("selected", [1, 1, 1, 0])] } } } )

style.theme_use("yummy")

note = ttk.Notebook(root)
f1 = ttk.Frame(note, width=300, height=200)
note.add(f1, text = 'First')
f2 = ttk.Frame(note, width=300, height=200)
note.add(f2, text = 'Second')
note.pack(expand=1, fill='both', padx=5, pady=5)

tk.Button(root, text='yummy!').pack(fill='x')

root.mainloop()

ttk tcl/tk

.

http://www.tcl.tk/man/tcl/TkCmd/ttk_notebook.htm

python pyttk-samples http://code.google.com/p/python-ttk/

+7

Oblivion , , / , Checkbuttons Text ( ). , , , ( ). , / / . , . . , , Oblivion .

Style().configure("TNotebook", background=myTabBarColor);
Style().map("TNotebook.Tab", background=[("selected", myActiveTabBackgroundColor)], foreground=[("selected", myActiveTabForegroundColor)]);
Style().configure("TNotebook.Tab", background=myTabBackgroundColor, foreground=myTabForegroundColor);

: -, Windows. Linux ( Xubuntu).

+3

Source: https://habr.com/ru/post/1536285/


All Articles