[Tkinter-discuss] Treeview: stop temporarily TreeviewSelect messages

Michael Lange klappnase at web.de
Wed May 31 18:34:48 EDT 2023


Hi Vasilis,

On Wed, 31 May 2023 14:44:35 +0000
Vasilis Vlachoudis <Vasilis.Vlachoudis at cern.ch> wrote:

> during the filling of a ttk.Treeview, widget I want to temporarily
> disable the <<TreeviewSelect>> (to restore the previously selected
> items), and re-enable it at the end. However, when I unbind the
> <<TreeviewSelect>> event the messages are still send. See the following
> demo code. I would expect that during the filling no <<TreeviewSelect>>
> message will be send, however I get hundreds of messages at the end
>

the problem appears to be that the binding is restored before the calls in
the "for" loop in your fill() function are processed. If we add a
strategic update() to your function it seems to work as expected:

def fill(event=None):
	t.unbind("<<TreeviewSelect>>")
	for i in range(1000):
		item = t.insert("",tk.END,text=f"Item {i}")
		if i&1==0: t.selection_add(item)
	t.update()
	t.bind("<<TreeviewSelect>>", tvselect)

update_idletasks() doesn't seem to be sufficient here.

Have a nice day,

Michael



More information about the Tkinter-discuss mailing list