python - Children not indenting using Tkinter Treeview - Stack Overflow

admin2025-04-17  3

I cant seem to figure out why the children of my tree are not indenting from their parent node and are lined up directly with them instead.

# Tree view initializers
# Tree Cloumns
filterTree = ttk.Treeview(m, show = 'tree headings')
filterTree['columns'] = ("ddm")
filterTree.column("#0", width = 40, stretch = FALSE)
filterTree.column("ddm", width = 120, stretch = TRUE)
treeScroll = ttk.Scrollbar(m, orient = 'vertical', command = filterTree.yview)
filterTree['yscrollcommand'] = treeScroll.set
# Tree Headers
filterTree.heading("#0", text = '', anchor = W)
filterTree.heading("ddm", text = "Select Option from one of the Drop Down Menus")
filterTree.grid(row = 3, columnspan=2, sticky = 'nsew')
# Tree Data
filterTree.insert(parent = '', index = 'end', iid = 'All Tickets', values = ('All Tickets'))
# Room Tree
filterTree.insert(parent = '', index = 'end', iid = "Room List", values = ('Room List',))
for record in netBr:
    if record == 'eof':
        break
    filterTree.insert(parent = 'Room List', index = 'end', iid = record, text = "", values = ("    " + record,))

I am currently adding the " " before the record name to forcefully indent the child but i would prefer not to have to do this and would just like to know what's causing it

I have tried lots of different ways of changing the column widths and features such as anchors, stretch, sticky, style. And different ways of initializing the children to their parent but always displays like this:

Without the " " forced indent at the beginning of the name it looks like this:

Everywhere i search online it looks like it just automatically indents children nodes in trees and i cant see that I'm doing something different from other examples even when i add a style to the tree which provides an indent option i still get the same results.

转载请注明原文地址:http://anycun.com/QandA/1744835065a88278.html