[Python] Change color of "tab header" in ttk.Notebook

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    Gretings!

    I want to change the color displayed in a tab header, created using ttk.Notebook. After search for a while I've found that to change the style of ttk widgets, we can use ttk. Styling, because Notebook apparently do not have configuration options to change its colors. However, I only found how to change the background and the foreground of a NoteBook object, but not how to configure the "tab header", whose background is either white (when selected) or grey (when not selected).

    Anybody can help me with this?

    This is the code that I have for now, related with 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.

    Continue reading...

Compartilhe esta Página