To this code we will add few more rows where some rows are child of parent row. The identification of parent and child is done by the values for parent option and the iid.
The child will have to iid of parent as option.
open=True/False
By default the child row can be displayed by using open=True. If this value is set to False then child will be in collapsed state, however it can be displayed by expanding the Tree ( + symbol ) in tree view and by double clicking in headers view.
show option
headings: Show the headings without the column marked as #0 tree: Show tree view with expanding the child node. No header row. tree headings : (Default) Show both heading and expanding child node. '' : Neither tree view nor headings are shown.
The full code with parent - child in Treeview is here.
my_list=[]
for child in trv.get_children():
my_list.append(trv.item(child)["values"][1])
#print(trv.item(child)["values"])
#print(trv.item(child)["values"][1]) # for Name
print(my_list)
Inserting User entered data
By using Entry widgets we can add row data to Treeview. Here based on the selection of the row, the input data will be stored as child row or can be stored as root or parent row.
On selection of any row of the Treeview, we can collect the iid ( parent id ) of the row and kept as default value for Parent id input. User can change the parent id or keep as blank to set the input data as root or parent row.
Inserting user input data as child or parent item to a Tkinter Treeview by using Entry widgets