简体   繁体   English

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

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

I want to change focus and selection from tk entry to ttk treeview section with binding key.我想使用绑定键将焦点和选择从 tk 条目更改为 ttk treeview 部分。

在此处输入图像描述

Above figure, present cursor and focus in entry section and want to move focus and selection to ttk treeview section上图,当前 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)

with focus, selection method, I can highlight specific list of item in treeview but I can't move item list by up and down key on keyboard because cursor still in entry.通过焦点,选择方法,我可以突出显示 treeview 中的特定项目列表,但我无法通过键盘上的上下键移动项目列表,因为 cursor 仍在条目中。

If I click directly list of items in treeview with mouse, I can move up and down of lists with my keyboard.如果我用鼠标直接单击 treeview 中的项目列表,我可以用键盘上下移动列表。

My question is how can I focus treeview section and can use my keyboard for selecting items in treeview section without mouse clicking.我的问题是如何聚焦 treeview 部分,并且可以使用我的键盘在 treeview 部分中选择项目而无需单击鼠标。

I found out what is problem.我发现了问题所在。

should use focus_set() method first for selecting and focusing whole treeview应该首先使用 focus_set() 方法来选择和聚焦整个 treeview

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

above sequence, I can select last items of treeview and can move lists with my keyboard以上序列,我可以 select treeview 的最后一项,并且可以用我的键盘移动列表

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

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