We can get the text of selected items in a treeview widget.
.selection() method
The .selection()
method returns the iid
of all selected items.
1 2 3 4 |
|
In the animated GIF above, I002 is the Pizza item, I003 is the Juice Slice item. The .selection() method returns the selected items as a tuple.
If there are no selections in the treeview, the .selection() method will return an empty tuple. It will not raise an exception.
Get selected item row text
Once we know the iid
of the selected item(s), we can get the row text that is displayed in the treeview.
First, we have to get the item’s details as a dictionary using .item()
1 2 3 4 5 6 7 8 9 10 11 12 |
|
If there are no selections in the treeview, the .selection() method will return an empty tuple. It will not raise an exception.