ttk.Treeview – get selected item index number

We can get the index number of a selected item in a treeview widget.

The index number is useful if you want to move the selected item to another index position.

img

# Get the selected item iid
selected_iid = treeview_test.selection()

# Get the index of the item based on the iid
item_index = treeview_test.index(selected_iid[0])