I have a Treeview in tkinter (Python 3.6 on Linux, but the same happens on windows) which I'm using to emulate a sort of spread-sheet layout. My problem is that, if I run the example code, below, and resize say "Column 1" then as "Column 1" gets bigger, "Column 2" gets smaller. However, if I drag out the final column to the right, the scroll bar expands, and now I can resize column 1 without changing the size of column 2 (instead the whole tree view expands). If you then resize, say, column 1 again, until all columns fit in the view, the behaviour seems to revert to the original.
What causes this change of behaviour? Both, how can I stop it, and how can I ensure it's the default?
Minimal working example:
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
tree = ttk.Treeview(root)
tree["show"] = "headings"
tree["columns"] = list(range(3))
for i in range(3):
tree.heading(i, text="Column {}".format(i))
for i in range(5):
tree.insert('', "end", i)
tree.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.E, tk.W))
xs = ttk.Scrollbar(root, orient=tk.HORIZONTAL, command=tree.xview)
tree["xscrollcommand"] = xs.set
xs.grid(row=1, column=0, sticky=(tk.E, tk.W))
root.mainloop()