Command for clicking on the items of a Tkinter Treeview widget?

Viewed 48970

I'm creating a GUI with Tkinter, and a major part of the GUI is two Treeview objects. I need the contents of the Treeview objects to change when an item (i.e. a directory) is clicked twice.

If Treeview items were buttons, I'd just be able to set command to the appropriate function. But I'm having trouble finding a way to create "on_click" behavior for Treeview items.

What Treeview option, method, etc, enables me to bind a command to particular items and execute that command "on_click"?

3 Answers

I know this is old but this code will also print multiple selected item in a treeview.

def on_double_click(self, event):
    item = self.tree.selection()
    for i in item:
        print("you clicked on", self.tree.item(i, "values")[0])
Related