返回 Tkinter Treeview iid [英] Returning Tkinter Treeview iid

查看:25
本文介绍了返回 Tkinter Treeview iid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个树形视图,并在其中插入了一些数据,如下所示.

I have a treeview and have inserted some data into it as shown below.

self.tree.insert('', 'end', iid="test1", text="test a", values=("data1", "data2"))

这会在树视图的末尾添加一个条目,其中包含文本test a"和data1"和data2"列值.

This adds an entry to the end of the treeview with text "test a" and column values of "data1" and "data2".

iid 已设置为test1".

The iid has been set to "test1".

我想返回树视图中项目的 iid 的值,以便我可以将它用于其他一些功能(我将在此 iid 中存储文件路径)

I would like to return the value of iid of an item in the treeview so that I can use it for some other function (I will be storing a file path in this iid)

我尝试使用 treeview.item() 并且返回了没有 iid 的以下字典:

I tried using treeview.item() and this returned the following dictionary without the iid:

{'version': 'data1', 'author': 'data2'}

(其中版本和作者是列标题)

(where version and author are the column headings)

所以我的问题是:有没有一种简单的方法可以将给定行/条目的 iid 返回到树视图?

So my question: is there a simple way to return the iid of a given row/entry to the treeview?

推荐答案

要获得 iid,您可以使用 identify() 函数:

To get the iid you can use the identify() function:

tree.identify(event.x, event.y) # item at row "x" and column "y"

iid 参数代表 item identifier,它对于每个 item 都是唯一的,您可以为其赋予所需的值.

The iid argument stands for item identifier which is unique for each item, and you can give it the value you want.

这篇关于返回 Tkinter Treeview iid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆