Python Forum
How to iterate through sub-children in TkTree?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to iterate through sub-children in TkTree?
#1
            for children in self.points_tree.get_children():
                child = self.points_tree.item(children)
                print(child)
This works perfectly for iterating through the parent children in the tree, but how do I iterate through the sub-children of each parent within the tree? I've attached an image for visual purposes.

Omg, Found the solution once again. Or at least a solution for now.

import tkinter as tk
import tkinter.ttk as ttk

def get_sub_children():
    for children in tree.get_children():
        child = tree.get_children(children)
        print(children, child)

root = tk.Tk()

btn = tk.Button(root, text='press', command=lambda: get_sub_children())
tree = ttk.Treeview(root, columns=1)
tree.pack(fill='both', expand=True)
btn.pack(side='top')

tree.insert("", tk.END, values='1')

for i in range(1, 5):
    for children in tree.get_children():
        tree.insert(children, tk.END, values=i)

root.mainloop()
this seemed to do the trick for me.
Output:
I001 ('I002', 'I003', 'I004', 'I005')

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Get class 's children on init panoss 3 6,499 Jan-06-2017, 08:11 AM
Last Post: panoss

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020