如何在没有鼠标的情况下使用键盘 select 树视图中的数据
how to using keyboard to select data in treeview without mouse
首先,当我的光标位于输入框(entrybox.focus()
)时,我想使用键盘上的 F4 键(GUI.bind('<F4>', directselection)
)来 select 我的第一个数据直接使用 treeview 而不是使用鼠标。
我不知道要创建函数。我正在尝试使用
def directselection(event = None):
treeviewtable.focus()
但是没用。
使用.get_children()
获取行ID列表,然后使用.selection_set()
到select第一行:
def directselection(event=None):
# get all row IDs
idlist = treeviewtable.get_children()
if idlist:
# select and focus on first row
treeviewtable.selection_set(idlist[0])
treeviewtable.focus(idlist[0])
# transfer keyboard focus to treeviewtable
treeviewtable.focus_force()
首先,当我的光标位于输入框(entrybox.focus()
)时,我想使用键盘上的 F4 键(GUI.bind('<F4>', directselection)
)来 select 我的第一个数据直接使用 treeview 而不是使用鼠标。
我不知道要创建函数。我正在尝试使用
def directselection(event = None):
treeviewtable.focus()
但是没用。
使用.get_children()
获取行ID列表,然后使用.selection_set()
到select第一行:
def directselection(event=None):
# get all row IDs
idlist = treeviewtable.get_children()
if idlist:
# select and focus on first row
treeviewtable.selection_set(idlist[0])
treeviewtable.focus(idlist[0])
# transfer keyboard focus to treeviewtable
treeviewtable.focus_force()