tag_configure is not working while using theme ttk treeview
On windows 10, Python 3.9.0, I've the same problem. Altering font with tag_configure works fine, but not background nor foreground. I'm new to tkinter, spend many hours on this problem and found the above solution after I had a workaround - with a copy of the actual used theme everything seams to work.
My workaround:
style = ttk.Style(self) aktualTheme = style.theme_use() style.theme_create("dummy", parent=aktualTheme) style.theme_use("dummy")
The program to isolate the problem. With zebra = 0 (line 10), I don't get the expected result
import tkinter as tkfrom tkinter import ttkclass App(tk.Tk): def __init__(self): super().__init__() self.title('Treeview Zebra') self.geometry('620x250') zebra = 1 if zebra: style = ttk.Style(self) aktualTheme = style.theme_use() style.theme_create("dummy", parent=aktualTheme) style.theme_use("dummy") self.tree = ttk.Treeview(self, columns=('F1', 'F2'), show='headings') self.tree.heading('F1', text='Field 1') self.tree.heading('F2', text='Field 2') self.tree.pack() # tags to tree self.tree.tag_configure('odd', background='#E6B3FF') self.tree.tag_configure('even', background='#DD99FF', foreground='white') self.tree.tag_configure('A10', background='#E6B3FF', font='Arial 10') self.tree.tag_configure('S', background='#DFDFDF', font=('Calibri', 9, 'bold')) # adding generated sample data to the treeview for n in range(1, 7): if n % 2 : self.tree.insert('', tk.END, values=(f'first {n}', f'last {n}', f'email{n}@example.com'), tags = ('S')) else: self.tree.insert('', tk.END, values=(f'first {n}', f'last {n}', f'email{n}@example.com'), tags = ('even', 'A10'))if __name__ == "__main__": app = App() app.mainloop()