Returning Tkinter Treeview Iid
Solution 1:
To get the iid
you can use the identify()
function:
tree.identify(event.x, event.y) # item atrow "x" andcolumn "y"
The iid
argument stands for item identifier which is unique for each item, and you can give it the value you want.
Solution 2:
Learning Python, found no answer to this question here that I liked, so I finally figured out what I wanted and thought I would post what I found. iid = tree.focus() returns the information requested.
in my treeview i added this code:
for item in tree.selection():
item_child = tree.get_children(item)
item = tree.item(item)
iid = tree.focus()
print ("iid = ", iid, "Item = ", item, "Child iid's =", item_child)
this is my result from the code:
{'text': 'TRAINS', 'image': '', 'values': '', 'open': 0, 'tags': ['m']}
iid = 1 Item = {'text': 'TRAINS', 'image': '', 'values': '', 'open': 0, 'tags': ['m']} Child iid's = ('8', '9', '10')
Notice at the beginning of line two of the result the iid is listed as "1" which is the correct iid for the item. All treeview items I select returned the correct iid.
Hope this helps the next person a little.
Solution 3:
Another solution is iid=tree.focus()
Post a Comment for "Returning Tkinter Treeview Iid"