I looked for and tested many similar questions/answers/possible duplicates here on SO and other sites but I'm interested specifically in using the solution below for simplicity's sake and minimal reproducible example constraint satisfaction.
Why does the following modification of this previous answer's code does not work/how to make it work?
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
tree = ttk.Treeview(root)
tree.pack(fill="both", expand=True)
items = []
for i in range(10):
item = tree.insert("", "end", text="Item {}".format(i+1))
items.append(item)
items_to_select = items[:]
def select_all_items(event):
tree.selection_set(items_to_select)
tree.bind('<Button-1>', select_all_items)
root.mainloop()
The original answer works as is.
I'm looking for a way to make it work with mouse event Button-1 click. The result should execute the selection of all items in the treeview when users click on any one item with the left mouse button (Button-1).
get_children()methoddef select_all_items(event): tree.selection_set(tree.get_children())with working script here: pastebin.com/3KWWFBwY (might not work with the loop version)