【发布时间】:2021-07-22 23:51:42
【问题描述】:
假设我有一个带有列表框的窗口。将项目插入我的列表框后,我想用向下箭头键移动选择,按下它后我看到选择移动到列表中的最后一个项目。
为什么按向下箭头会选择列表中的最后一个元素而不是第二个?需要做什么来恢复正确的选择顺序?
示例应用
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()
【问题讨论】:
-
当我按下向下箭头键时,它不会选择列表中的最后一个元素