Skip to content Skip to sidebar Skip to footer

Unable To Change Background Color Of Treeview In Python

I am trying to change the background color of the rows in treeview using tags but unable to get the success. Following is my code: def display_device_status(self, colnames): #

Solution 1:

You are changing the color of the rows the right way, but there is currently a bug with treeviews in Tcl: https://core.tcl-lang.org/tk/tktview?name=509cafafae so the row color set from the tag is overridden by the treeview background color set by the style.

While waiting for the fixed version of tcl/tk, you can use the fix suggested in the bug ticket:

style = ttk.Style()

deffixed_map(option):
    # 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-safereturn [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"))

Post a Comment for "Unable To Change Background Color Of Treeview In Python"