I want to be able to adjust the color of a ttk.Frame()
widget. I know this question has been asked numerous times here. A very useful answer was given here: Change color of "tab header" in ttk.Notebook. One can do this using style.theme_create()
.
I want to make a similar adjustment using ttk.Style()
but cannot figure out how. Could someone explain to me how I can do this?
The reason I am not using the method proposed in the above link is because there are other widgets in my code that I want to (and can) customize using ttk.Style()
.
import tkinter as tk
from tkinter import ttk
class Window():
def __init__(self, parent):
self.parent = parent
self.parent.minsize(width=600, height=400)
self.widgets()
def widgets(self):
s1 = ttk.Style()
s1.configure('My.TNotebook.Tab', padding=5, background='red')
s1.map('My.TNotebook.Tab', background=[('selected', 'green')])
self.nb1 = ttk.Notebook(self.parent, style='My.TNotebook.Tab')
self.tab1 = ttk.Frame(self.nb1)
self.tab2 = ttk.Frame(self.nb1)
self.tab3 = ttk.Frame(self.nb1)
self.nb1.add(self.tab1, text='Tab1')
self.nb1.add(self.tab2, text='Tab2')
self.nb1.add(self.tab3, text='Tab3')
self.nb1.place(relx=0.1, rely=0.1, width=500, height=200)
self.b1 = ttk.Button(self.parent, text='Quit', command=self.quit)
self.b1.place(relx=0.4, rely=0.7, height=70, width=150)
def quit(self):
self.parent.destroy()
root = tk.Tk()
app = Window(root)
root.mainloop()