0

Lets say I have window with Listbox. After inserting items to my listbox I want to move selection with down arrow key, after pressing it i see that selection moved to last item on the list.

Why pressing down arrow selects last element on the list and not second one? What needs to be done to restore proper order of selection?

Example app

from tkinter import *


root = Tk()
root.bind('<Escape>', lambda e: root.quit())
listbox = Listbox(root)
listbox.insert(END, *[i for i in range(20)])
listbox.pack()
listbox.focus()
listbox.selection_set(0)

# now, changing selection with down arrow key goes to last element on the list not second one

root.mainloop()
BPS
  • 1,133
  • 1
  • 17
  • 38

1 Answers1

3

If you scroll down, you will notice the last item is "activated", you need to activate your first item too, so:

listbox.selection_set(0)
listbox.activate(0)
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46