PotatoBeenCrafted
PotatoBeenCrafted

Reputation: 312

Python Tkinter TTK Treeview Find Selected Items' ID Or Row

I am creating a program which uses a TTK Treeview as an item hierarchy. So far, the user is able to insert their own values into the tree, but I need to have a check running for when the user clicks on an item in the tree. I need the check to find the selected items ID and return it.

The check I have running relies on the <<TreeviewSelect>> bind. Currently, it finds the selected item and stores some information, but I need for it to also find the row the item is in or it's ID.

I tried implementing my own tag using a counter and the tag attribute of Treeview items, but it would return the number as a NoneType. I also tried using the value attribute, but it returned the same problem.

For information, I have read through many sites and a few questions on here, but none (that I have found) answer what I need.

Any help would be greatly appreciated, thank you for taking the time to read.

Upvotes: 0

Views: 3820

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386352

You can call the selection method to get a list of all selected items:

selected_items = self.tree.selection()

Upvotes: 2

Related Questions