如何在tkinter中的所有标签上执行tag_bind

时间:2016-05-06 07:16:59

标签: python tkinter

我有一个TreeView小部件,我插入了一些项目,并有选择地在其中一些项目上应用了一些标签。现在我想将click事件绑定到窗口小部件中的所有项目,但绑定语法如下所示:

treeView.tag_bind(tag_name, event_sequence, click_handler)

我的问题是我想对所有标签以及未标记的项目执行此操作。是否有类似.tag_bind_all的内容?

2 个答案:

答案 0 :(得分:0)

使用列表或功能。假设你想要绑定所有标签:

for this_tag in [tag_name1, tag_name2, tag_name3]:
    treeView.tag_bind(this_tag, event_sequence, click_handler)

答案 1 :(得分:0)

我想出来了,这样做了:

treeView.bind('<<TreeviewSelect>>', lambda *x:self.__treeViewItemSelected())

然后在我可以做的方法内:

item_id = treeView.focus()
value = treeView.item(item_id)