【问题标题】:how to using keyboard to select data in treeview without mouse如何在没有鼠标的情况下使用键盘在树视图中选择数据
【发布时间】:2021-02-03 04:37:38
【问题描述】:

首先,当我的光标在输入框(entrybox.focus())时,我想使用键盘上的 F4 键(GUI.bind('<F4>', directselection))直接选择树视图中的第一个数据,而不是使用鼠标。

我不知道要创建这个函数。我正在尝试使用

def directselection(event = None):
    treeviewtable.focus()

但它不起作用。

【问题讨论】:

    标签: python tkinter treeview ttk


    【解决方案1】:

    使用.get_children() 获取行ID 列表,然后使用.selection_set() 选择第一行:

    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()
    

    【讨论】:

    • 谢谢!这是工作。但是如果你不介意的话,光标仍然集中在输入框上请帮助:)
    猜你喜欢
    • 1970-01-01
    • 2017-08-04
    • 1970-01-01
    • 2011-11-26
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    相关资源
    最近更新 更多