I have a ttk.Treeview widget with some rows of data. How do I set the focus to and select (highlight) a specified item?
tree.focus_set()
does nothing
tree.selection_set(0)
complains that: Item 0 not found, although the widget is plainly populated with more than zero items. Trying item 1 does no better.
EDIT: to select an item, find its id, then use tree.selection_set(id). Neither tree.focus(id) nor tree.focus_set(id) appears to do anything.
Get the id of treeview item you want to highlight/select
child_id = tree.get_children()[-1] # for instance the last element in tuple
To highlight the item, use both focus()
and selection_set(item_id)
tree.focus(child_id)
tree.selection_set(child_id)
Note: I haven't worked with python.
Looking at this link, the focus
method with optional parameter item, should highlight the node.
If not, look at selectmode
option & set it to "browse"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With