How do I get the Node ID (i.e. niid
) of all nodes in a ttk.Treeview
with a certain tagname?
CodePudding user response:
What you need is the function .tag_has(tag_name)
.
For example:
...
columns = list(range(1,3))
tree = ttk.Treeview(root, columns=columns)
tree.insert('', 'end', iid=1, values=(1,1), tags='1')
tree.insert('', 'end', iid=2, values=(2,2), tags='1')
tree.insert('', 'end', iid=3, values=(3,3), tags='3')
tree.insert('', 'end', iid=4, values=(4,4), tags='1')
tree.insert('', 'end', iid=5, values=(5,5), tags='2')
print(tree.tag_has('1'))
...
The output will be:
('1', '2', '4')