Search code examples
pythonpython-3.xtkintertreeviewttk

Is there a way to make a ttk.Treeview fill vertical space (sticky N+S)?


I have a layout where the main item is a ttk.Treeview, so I would like for it to fill the available space. It does so horizontally, but not vertically. Here is the code for the relevant frame:

f_right = Frame(f_main, relief=RELIEF, borderwidth=BWIDTH, padding=PADDING)
f_right.grid(column=2, row=0, sticky = E+N+S)

entry = tk.Entry(f_right)
entry.grid(column=0, row=0, sticky = N)

Style(root_window).configure("Treeview",rowheight=FONT_HEIGHT,background="black",
    foreground="white",fieldbackground="black")

tree = ttk.Treeview(f_right, style = "Treeview")
tree.grid(column=0, row=1, sticky = W+E+N+S)

The frame f_right fills vertically, so there is plenty of space for the tree to grow.

Since everything else is laid out using grid(), I cannot use pack().

Is there anything I can do to make the Treeview use up the vertical space?


Solution

  • Well, thanks to @stovl I found out that it has nothing to do with the Treeview, but I simply neglected to read the tkinter documentation carefully enough. You have to set a nonzero weight to the row to make it expand.

    What does 'weight' do in tkinter?