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



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

treeView.tag_bind(tag_name, event_sequence, click_handler)

我的问题是,我想对所有标签和未标记的项目都这样做。有类似.tag_bind_all的东西吗?

使用列表或函数。假设你想绑定所有标签相同:

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

我发现了这一点,它做到了:

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

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

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

最新更新