Hello,
Just wondering if someone can give me a small hint on how to bind the up/down arrow keys successfully to a Tk Listbox.
So far I have:
### Down Arrow Binding
bind .top.lis33 {
set i [.top.lis33 activate [expr [.top.lis33 curselection]+1]]
.top.lis33 itemconfigure active -selectbackground blue -selectforeground white
}
### Up Arrow Binding
bind .top.lis33 {
set i [.top.lis33 activate [expr [.top.lis33 curselection]-1]]
.top.lis33 itemconfigure active -selectbackground blue -selectforeground white
}
Am I anywhere close to such a solution for these bindings?
Help much appreciated.
The arrow keys and several other key bindings already exist on the Listbox. However, the widget must have focus for it to receive key bindings, and focus isn't given to a listbox by default when clicking on it. You can force focus in an instance with [focus], or do it for all listboxes with:
bind Listbox {+ focus %W;}