Skip to content Skip to sidebar Skip to footer

Ttk.treeview - How To Change Selection Without Clicking First

I thought setting a row to be selected by default in ttk.Treeview would make it unnecessary to click first to start using the arrow buttons on the keyboard to change the selection.

Solution 1:

I tried several online examples of Treeview widgets and they all have to have a row clicked before the arrow keys will be able to change the selection. How can this be overriden?

Sadly, the ttk widgets are a bit quirky. You need to make sure the widget as a whole has focus, that an item is selected, and the selected item needs to have the focus. You've done the first two but not the third.

Add the following after calling focus_set():

tree.focus('gallery1')

Post a Comment for "Ttk.treeview - How To Change Selection Without Clicking First"