I’m having a treeview element in a frame to the left, which shares the space with another element to the right, in this test case here it’s a button. When the window is resized to a smaller size, the treeview does not shrink, but the button does. The treeview only starts shrinking, when the button isn’t visible any more. It seems that the columns have something like a fixed minimum size.
Here is a test program, which shows the problem:
from tkinter import *
from tkinter import ttk
root = Tk()
root.geometry("400x200")
upper_container = Frame(root)
upper_container.pack(fill="x")
left_tree = ttk.Treeview(upper_container, column=("c1", "c2"))
left_tree.column("# 0", anchor=CENTER)
left_tree.heading("# 0", text="ID")
left_tree.column("# 1", anchor=CENTER)
left_tree.heading("# 1", text="Test")
left_tree.pack(side=LEFT, fill="x", expand=True)
right_button = ttk.Button(upper_container, text="Button")
right_button.pack(side=LEFT, fill="x", expand=True)
root.mainloop()
My expected behaviour would be, that both elements start shrinking. I tried using .grid instead of .pack, but the behaviour stays the same. Maybe I’m missing out on some thing.
Björn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.