Python Tkinter Treeview:行着色

问题描述 投票:0回答:1

我已经在 Tkinter Python 中创建了一个树视图表,并且到目前为止只填充了一项。该项目对应于表的第一行。该行的颜色设置为绿色。当通过单击选择该行时,其颜色变为蓝色,但是当我单击空白区域以取消选择该行并将其恢复为原始颜色时,它不起作用;它保持蓝色,直到我重新运行应用程序,这作为解决方案是不切实际的。因此我要求一个更好的。

感谢任何愿意帮助我解决这个问题的人。

python tkinter colors treeview selecteditem
1个回答
0
投票

单击 Treeview 小部件内的

空白区域
不会更改当前选择。

默认情况下

selectmode
,您可以在所选项目上使用Ctrl单击取消选择。

如果您想在点击空白处时清除选择,您可以在绑定

<Button-1>
事件的回调中执行此操作:

def on_click(event):
    table = event.widget
    item = table.identify_region(event.x, event.y)
    if item == "nothing":
        table.selection_remove(table.selection())

# assume table is the Treeview widget
table.bind("<Button-1>", on_click)
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.