Why does my ttk.Treeview click handler return the wrong item on tree.focus()? Why does my ttk.Treeview click handler return the wrong item on tree.focus()? tkinter tkinter

Why does my ttk.Treeview click handler return the wrong item on tree.focus()?


This is the way Tkinter is designed to work. Bindings on a widget are processed before bindings on the widget class. It is the bindings on the widget class that set the selected item. This makes it really easy to override the default bindings, at the expense of making it slightly harder to augment default bindings.

This has been asked a few times on this site. Search for "bindtags" on this site; bindtags are the mechanism that controls the order of event processing.

In the specific case of the treeview widget, I recommend binding to the <<TreeviewSelect>> event, which will be processed after the selection has been set. You can then use the tag_has method to determine what sort of node was clicked on.