繁体   English   中英

使用绑定键将焦点和选择从 tk 条目移动到 ttk treeview

[英]Move focus and selection from tk entry to ttk treeview with binding key

我想使用绑定键将焦点和选择从 tk 条目更改为 ttk treeview 部分。

在此处输入图像描述

上图,当前 cursor 和焦点在入口部分,想要将焦点和选择移动到 ttk treeview 部分

    def treeview_focus(self, event):

    child_id = self.tree.get_children()[-1]
    
    self.tree.focus(child_id)
    self.tree.selection_set(child_id)
    self.tree.selection_add(child_id)

通过焦点,选择方法,我可以突出显示 treeview 中的特定项目列表,但我无法通过键盘上的上下键移动项目列表,因为 cursor 仍在条目中。

如果我用鼠标直接单击 treeview 中的项目列表,我可以用键盘上下移动列表。

我的问题是如何聚焦 treeview 部分,并且可以使用我的键盘在 treeview 部分中选择项目而无需单击鼠标。

我发现了问题所在。

应该首先使用 focus_set() 方法来选择和聚焦整个 treeview

self.tree.focus_set()
self.tree.focus(child_id)

以上序列,我可以 select treeview 的最后一项,并且可以用我的键盘移动列表

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM