0

This is the screenshot of my treeview in python tkinter.. I want to change the foreground of "Critical Level" including its children to "Red" or at least red.

style = Style()
        style.configure("mystyle.Treeview", highlightthickness=0, bd=0, font=('open sans', 10), rowheight=20,
                        foreground='#e8e8e8')
        style.configure("mystyle.Treeview.Heading", font=('open sans', 10, 'bold'), foreground='#000000')

2 Answers2

2

You can do so by tagging your treeview item instead, and use tag_configure to change the displayed colour.

from tkinter import ttk
import tkinter as tk

root = tk.Tk()
tree = ttk.Treeview(root)
tree.pack()
c = tree.insert('', 'end', text='This is critical message', tags=('critical',))
tree.insert(c, 'end', text='This is child of critical message', tags=('critical',))
for i in range(5):
    tree.insert('', 'end', text='This is non-critical message')
tree.tag_configure('critical', background='red',foreground="white")

root.mainloop()
Henry Yik
  • 22,275
  • 4
  • 18
  • 40
0

Be aware: Henry Yik's answer won't work in python 3.7.3 and 3.8.0. However, it works in python 3.6.2.

You can find difference in behaviour using code from answer: How to fully change the background color on a tkinter.ttk Treeview

Acid Ascorbic
  • 43
  • 1
  • 6