When you want to select an item in a Treeview, you usually use the double-click:
def print_element(event):
print(my_treeview.selection()[0])
my_treeview.bind("<Double-1>", print_element)
Today I tried to do the same but using a single click instead:
my_treeview.bind("<Button-1>", print_element)
But it wouldn't work. The output was just an empty tuple. I started to search online for an explanation... why is it not working?
EDIT:
My goal was actually to do something
every time a treeview item was selected.
- I proposed a solution myself using the
identify()
function of Tkinter - Another user proposed to use the Tkinter callback
<ButtonRelease-1>
which is much more appropriate - Finally, a third user focused his answer on using the Tkinter callback
<<TreeviewSelect>>
, which is for sure the best option