2024-05-11 18:56:20 发布
网友
我有一个ttk.Treeview小部件,里面有一些数据行。如何将焦点设置为并选择(突出显示)指定项?
tree.focus_set()
什么都不做
tree.selection_set(0)
抱怨:找不到项0,尽管小部件显然填充了超过零个项。尝试第1项也没什么好的。
编辑:选择一个项目,找到它的id,然后使用tree.selection_set(id)。tree.focus(id)和tree.focus\u set(id)都不起作用。
注意:我没有和python打过交道。
查看this链接,带有可选参数项的focus方法应该突出显示节点。
focus
如果不是,请查看selectmode选项,并将其设置为"browse"。
selectmode
"browse"
获取要突出显示/选择的treeview项的id
child_id = tree.get_children()[-1] # for instance the last element in tuple
要突出显示该项,请同时使用focus()和selection_set(item_id)
focus()
selection_set(item_id)
tree.focus(child_id) tree.selection_set(child_id)
当我想解决同样的问题时,遇到这个问题。
发现这个:
tree.selection_set(item)突出显示项目
tree.selection_set(item)
tree.focus(item)或tree.focus_set(item)选择项
tree.focus(item)
tree.focus_set(item)
注意:我没有和python打过交道。
查看this链接,带有可选参数项的
focus
方法应该突出显示节点。如果不是,请查看
selectmode
选项,并将其设置为"browse"
。获取要突出显示/选择的treeview项的id
要突出显示该项,请同时使用
focus()
和selection_set(item_id)
当我想解决同样的问题时,遇到这个问题。
发现这个:
tree.selection_set(item)
突出显示项目tree.focus(item)
或tree.focus_set(item)
选择项相关问题 更多 >
编程相关推荐