How to change background/foreground of item in Treeview by tag? How to change background/foreground of item in Treeview by tag? tkinter tkinter

How to change background/foreground of item in Treeview by tag?


A solution is found at: https://bugs.python.org/issue36468

According to the link, the issue is with the Tkinter version. People are thinking the issue is with the Python version but that is because the Python version uses the faulty Tkinter version.

def fixed_map(option):# Fix for setting text colour for Tkinter 8.6.9# From: https://core.tcl.tk/tk/info/509cafafae## Returns the style map for 'option' with any styles starting with# ('!disabled', '!selected', ...) filtered out.# style.map() returns an empty list for missing options, so this# should be future-safe.return [elm for elm in style.map('Treeview', query_opt=option) if  elm[:2] != ('!disabled', '!selected')]style = ttk.Style()style.map('Treeview', foreground=fixed_map('foreground'),       background=fixed_map('background'))


I'm quite sure that the 'tags' keyword must get a tuple instead of a string, to force the conversion, just write 'minus' like ('minus',) instead.

Edit: Documentation actually says that the 'tags' keyword should actually get a list, but i've seen lots of examples that supply a tuple. I suppose that this is due to the fact that a tuple can be parsed to a list.