1

I added the following code (taken from this post), however I didn't get the desired solution.

def change_colour():
    trv.set(trv.selection()[0],0,tags='changed_tag')        #this causes problem
    trv.tag_configure("changed_tag",foreground="blue",background="yellow")

When executed I get this error (from the first line of the function):
TypeError: set() got an unexpected keyword argument 'tags'

My goal is to change the tag of the selected item (in treeview), so it's colour will be changed.

2 Answers2

2

I found a solution myself, for anyone with the same problem:

    def high_target():
        selected_item = trv.selection()[0]
        trv.item(selected_item, tags='changed_tag')
        trv.tag_configure("changed_tag",foreground="blue",background="yellow")
  • You don't need to configure the tag here. Usually it's best to configure the tags at the time that you create the `Treeview` widget. – Bryan Oakley Jan 02 '21 at 21:56
0

I think your code should be like this (didn't test it though):

def change_colour(iid):
    trv.item(iid, tags="changed_tag")
    trv.tag_configure("changed_tag", foreground="blue", background="yellow")

and where you create your treeview items with trv.insert, store the value returned by trv.insert in a variable and pass it as an argument to change_colour. Example:

iid = trv.insert("", "end", values=("a", "b", "c"))
change_colour(iid)
TheEagle
  • 5,808
  • 3
  • 11
  • 39