[Tkinter-discuss] Treeview: stop temporarily TreeviewSelect messages

Vasilis Vlachoudis Vasilis.Vlachoudis at cern.ch
Wed May 31 10:44:35 EDT 2023


Hi all,

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

import tkinter as tk
from tkinter import ttk

def tvselect(event):
      print("SELECTION CHANGED")

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.bind("<<TreeviewSelect>>", tvselect)

if __name__ == "__main__":
      root = tk.Tk()
      t = ttk.Treeview(root)
      t.bind("<<TreeviewSelect>>", tvselect)
      t.pack(expand=tk.YES,fill=tk.BOTH)
      b = tk.Button(root, text="Press me", command=fill)
      b.pack()
      root.mainloop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/tkinter-discuss/attachments/20230531/5bed1113/attachment.html>


More information about the Tkinter-discuss mailing list