Hi Vasilis,

On Wed, 31 May 2023 14:44:35 +0000
Vasilis Vlachoudis <vasilis.vlachou...@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

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to