I don't have ads on this website.
Donations help keep this site going.

If you find tkinter-snippets.com useful, please donate any amount you feel comfortable with.
Visit https://ko-fi.com/jobinpy to donate. Thank you!

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])