i have created a Treeview and changed the selected color using this code:
style = self.style = ttk.Style(win)
style.theme_create("my", "vista",
settings={
'Treeview': {
'map': {
'background': [('selected', '#ffdddd'), ("!selected", "white")],
'foreground': [('selected', 'black')],
"font": [("", ("", 13))]
} # end 'map'
}, # end 'Treeview'
'TNotebook.Tab': {
'map': {
'font': [("", ("", 14))]
} # end 'map'
}, # end 'TNotebook.Tab'
'TNotebook': {
'map': {
'background': [("", "#eee")]
} # end 'map'
} # end 'TNotebook
} # end settings
)
style.theme_use("my")
The code works fine, but when i try to change background color of specific item's (rows) using tag_configure method nothing changes, i found that this is a tkinter bug, the solution is this code: (it is working without using the above theme)
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.map('Treeview', foreground=fixed_map('foreground'), background=fixed_map('background'))
so the problem is while i want to specify the selected background, i can't change background color of items and tag_configure is not affecting anything. am i missing something or is there any other way to do this?