I am configuring the TTK style of my notebook to have specific colors when select and not selected. You can see in the image that the margin color is the only thing that changed. The tabs didn't.
Also, the notebook and its tabs shouldn't have a border, but it becomes clear when looking at two nested notebooks like in the image. There should be no grey lines in the marked red areas.
The notebooks have a weird border around them which I am not sure where they come from. I tried to remove them using borderwidth
and highlightthickness
but it doesn't help.
Code to recreate the probelm:
from Tkinter import *
import ttk
root = Tk()
root.geometry("400x300")
# Setup style for Notebook:
style = ttk.Style()
style.configure('TNotebook', tabmargins=[2, 5, 2, 0],
background='orange', # margin color - should be orange
tabposition='wn', # makes the notebook vertical
borderwidth=0, # should help eliminate the annoying border
highlightthickness=0 # should help eliminate the annoying border
)
style.configure('TNotebook.Tab', padding=[5, 1],
background='red', # color of tab when NOT selected should be red
font=('URW Gothic L', '11', 'bold'),
borderwidth=0, # should help eliminate the annoying border
highlightthickness=0, # should help eliminate the annoying border
foreground='black' # font color
)
style.map('TNotebook.Tab',
background=[("selected",
'green' # color of tab when selected should be green
)],
expand=[("selected", [1, 1, 1, 0])])
# Create Demo window
MainNotebook = ttk.Notebook(root)
MainNotebook.pack(fill=BOTH, expand=True)
# Just an empty frame
Frame1 = Frame(MainNotebook, background="#000000", width=200, height=150, borderwidth=0, highlightthickness=0)
Frame1.pack(fill=BOTH, expand=True)
# frame that will hold the 2nd notebook
Frame2 = Frame(MainNotebook, background="#000000", width=200, height=150, borderwidth=0, highlightthickness=0)
Frame2.pack(fill=BOTH, expand=True)
MainNotebook.add(Frame1, text="Tab1")
MainNotebook.add(Frame2, text="Tab2")
# 2nd notebook that will have empty tabs
SecondNotebook = ttk.Notebook(Frame2)
SecondNotebook.pack(fill=BOTH, expand=True)
Frame3 = Frame(SecondNotebook, background="#000000", width=200, height=150, borderwidth=0, highlightthickness=0)
Frame3.pack(fill=BOTH, expand=True)
Frame4 = Frame(SecondNotebook, background="#000000", width=200, height=150, borderwidth=0, highlightthickness=0)
Frame4.pack(fill=BOTH, expand=True)
SecondNotebook.add(Frame3, text="Tab3")
SecondNotebook.add(Frame4, text="Tab4")
# For contrast
bottom_frame = Frame(root, background="#000000", width=200, height=150, borderwidth=0, highlightthickness=0)
bottom_frame.pack(fill=BOTH, expand=True, side=TOP)
root.mainloop()
Some of the sources I used when researching this problem: