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

John O'Hagan research at johnohagan.com
Sun Feb 12 06:10:20 EST 2023


On Mon, 2023-02-06 at 10:19 -0800, stefalem wrote:
> Il giorno sabato 4 febbraio 2023 alle 11:43:29 UTC+1 John O'Hagan ha
> scritto:
> ...
> 
> > Is there another way to do what I want? 
> 
> 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()

Thank you for your reply. Unfortunately that's not quite what I'm
after, because it unselects the flashing item.

My goal was to be able to change the colour of an individual item
regardless of whether it is selected or not. To do that, it is
necessary to be able to change the colour of an individual selected
item, without changing the selection or changing the colour of other
selected items. It seems this isn't possible.

Thanks

John


More information about the Python-list mailing list