tkinter ttk.Treeview: changing background colour of single item when selected

stefalem stefalem79 at gmail.com
Mon Feb 6 13:26:35 EST 2023


> Is there another way to do what I want? 

try this:

from tkinter import *
from tkinter.ttk import *

root = Tk()
t = Treeview(root)

t.insert('', 0, iid='item1', text='item1')
t.insert('', 1, text='item2')
t.tag_configure('flashtag', background='red')
t.pack()
  
def flash():
 tags = t.item('item1', 'tags')
 t.item('item1', tags='' if tags else 'flashtag')
 t.after(500, flash)
 itemselected = t.selection()
 for x in itemselected:
  if (x == 'item1'):
   t.selection_remove(t.get_children())

flash()
mainloop()



More information about the Python-list mailing list