簡體   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