0

I have tried using both separately and they work, but when I combine them under the same variable neither of them work. Is there a method of combining them both together? Here is the bit of my code which I am talking about:


sideTab = ttk.Style(screen)
sideTab.configure("tab.TNotebook", tabposition='wn')
tabColour = ttk.Style(screen)
tabColour.configure("colour.TNotebook", background="black")

newStyle = ("tab.TNotebook", "colour.TNotebook")

tabList = ttk.Notebook(screen, style=newStyle)

This code wouldn't change the style as both are being used in the 'style' Does anyone have any ideas how I could get them both to work?

j_4321
  • 15,431
  • 3
  • 34
  • 61
Jacob
  • 25
  • 10

1 Answers1

0

It is usually enough to create a single ttk.Style instance and configure the styles of all the widgets with it.

To combine styles, just choose one name, e.g. "custom.TNotebook" and configure the same options as in "colour.TNotebook" and "tab.TNotebook":

style.configure("custom.TNotebook", background="black", tabposition="nw")

and use this style for your notebook.

Full example:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
style = ttk.Style(root)
style.configure("custom.TNotebook", background="black", tabposition='wn')

tabList = ttk.Notebook(root, style="custom.TNotebook")
for i in range(4):
    tabList.add(ttk.Label(tabList, text=f"Content {i}"), text=f"Tab {i}")
tabList.pack(fill="both", expand=True)

root.mainloop()
j_4321
  • 15,431
  • 3
  • 34
  • 61