0

I created a window and use ttk notebook to view a tab menu. I am not able to change the text size and font ,background color etc for the tab menu.

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

How could I change the size and color of the text like "home","Alarm" etc individually?? style.configure('TNotebook.Tab', foreground='red') change the fore color of notebook and all the tab text color is changed. how could i change the color of text suppose "disconnected" ????

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Akash Nil
  • 693
  • 10
  • 26
  • you should check this https://stackoverflow.com/questions/23038356/change-color-of-tab-header-in-ttk-notebook – Abd El Kodous Souissi Apr 19 '19 at 12:46
  • create theme option works properly. thank you. is there any option to configure a tab dynamically. like note.configure(window.tab2,state="dusabled") @AbdElKodousSouissi – Akash Nil Apr 22 '19 at 11:04

1 Answers1

2

Here is a code I found, I edited it of course but it might help you about some of your demands such as color, (still don't know about text if any one can help by the way) :

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

EDIT : here is the link : https://www.programcreek.com/python/example/104109/tkinter.ttk.Notebook but note that i have explored all the example code and this example was the only one dealing with :

style.theme_create()

This function of ttk allow you to set up the whole theme of your app, what is done here is about going from parent class widget to child class and configure things such as background, foreground and so on. What i understood is that each of widget level have name, and an amount of paremeter that you can change and what you don't touch stay default. So here we are exploring the parent, then the TNotebook, then Tnotebook.Tab, then map wich is the lowest level. I'm working on it and figured out how to change the font color, add this parameter in the TNotbook.Tab configuration as I show below :

"TNotebook.Tab": {
        "configure": {"foreground":"white"}

EDIT : Another break through about the selected and disabled tab-button, about having two different colors here is how you can do, in "map" class of the upper code :

"map": {"foreground": [("selected", "black"),("!disabled", "white")] }

the " theme_settings " of tkinter doc is quite useful : https://docs.python.org/3/library/tkinter.ttk.html

Found how to change text font in this topic : How can I change the size of tab caption box and font of ttk notebook tabs?

  • Welcome to SO! I am curious, where did you find the code? May you explain what is doing? Please also consider https://stackoverflow.com/help/how-to-answer – B--rian Jan 24 '20 at 14:37