Re: [Tkinter-discuss] Treeview: stop temporarily TreeviewSelect messages
Hi Vasilis, On Wed, 31 May 2023 14:44:35 + Vasilis Vlachoudis wrote: > during the filling of a ttk.Treeview, widget I want to temporarily > disable the <> (to restore the previously selected > items), and re-enable it at the end. However, when I unbind the > <> event the messages are still send. See the following > demo code. I would expect that during the filling no <> > 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("<>") 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("<>", 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
[Tkinter-discuss] Treeview: stop temporarily TreeviewSelect messages
Hi all, during the filling of a ttk.Treeview, widget I want to temporarily disable the <> (to restore the previously selected items), and re-enable it at the end. However, when I unbind the <> event the messages are still send. See the following demo code. I would expect that during the filling no <> message will be send, however I get hundreds of messages at the end import tkinter as tk from tkinter import ttk def tvselect(event): print("SELECTION CHANGED") def fill(event=None): t.unbind("<>") for i in range(1000): item = t.insert("",tk.END,text=f"Item {i}") if i&1==0: t.selection_add(item) t.bind("<>", tvselect) if __name__ == "__main__": root = tk.Tk() t = ttk.Treeview(root) t.bind("<>", tvselect) t.pack(expand=tk.YES,fill=tk.BOTH) b = tk.Button(root, text="Press me", command=fill) b.pack() root.mainloop() ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss