Python Tkinter Treeview

编程入门 行业动态 更新时间:2024-10-25 19:31:37
本文介绍了Python Tkinter Treeview-迭代'get_children'输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我稍后尝试遍历Treeview内部的数据。

I am trying to later iterate through the data inside of the Treeview. I will then hope to be able to sort through it.

from tkinter import * from tkinter.ttk import * import pickle root = Tk() def treeData(event): children = tree.get_children() print(children) entry = StringVar() a = Entry(root, textvariable=entry) a.grid(column=0,row=0) a.bind("<Key>", function) file_data = [] file = open('data.dat', 'rb') while True: try: file_data.append(pickle.load(file)) except EOFError: break file.close() column_names = ("Column 1", "Column 2") tree = Treeview(root, columns=column_names) tree['show'] = 'headings' for x in file_data: a = tree.insert('', 'end', values=x) for col in column_names: tree.heading(col, text=col) tree.grid(column=0, row=1)

在函数中,当我打印(ch ildren),它输出的列表与此类似-('I001','I002','I003','I004')

In the function, called 'treeData' when I print(children) it outputs a list that looks similar to this - ('I001', 'I002', 'I003', 'I004')

我希望有人会知道如何将这些数据转换为Treeview行中实际显示的内容?

I am hoping someone will know how to convert these pieces of data into what is actually shown in the row of the Treeview?

谢谢

推荐答案

您要问的内容记录在官方的tkinter Treeview小部件的文档。

What you are asking is documented in the official tkinter documentation for the Treeview widget.

get_children 方法返回一个商品ID列表,每个孩子一个。树视图的 item 方法将返回数据字典给定项目。因此,您可以使用以下方式迭代这些值:

The get_children method returns a list of item IDs, one for each child. The item method of the treeview will return a dictionary of data for a given item. Thus, you can iterate over the values with something like this:

for child in tree.get_children(): print(tree.item(child)["values"])

更多推荐

Python Tkinter Treeview

本文发布于:2023-10-31 01:41:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   Tkinter   Treeview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!