Search code examples
python-3.xtkintertreeview

Tkinter, treeview doesn't resize


How can I make the treeview resize when I resize the window in height ? I tried to set sticky="sn", I tried to pack the treeview with fill='y', but nothing worked.

import tkinter as tk
from tkinter.ttk import Treeview

root = tk.Tk()

f1 = tk.Frame(root)
f2 = tk.Frame(root)

f1.grid(column=0, row=0, sticky="s")
f2.grid(column=1, row=0, sticky="n")
root.rowconfigure(0, weight=1)

Treeview(f1).pack()
tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
tk.Button(f2, text="DAT BUTTON IS IN F2").pack()

root.mainloop()

Solution

  • You need sticky="ns" to resize Frame in window and fill='y', expand=True to resize Treeview in Frame

    import tkinter as tk
    from tkinter.ttk import Treeview
    
    root = tk.Tk()
    
    f1 = tk.Frame(root)
    f2 = tk.Frame(root)
    
    f1.grid(column=0, row=0, sticky="ns")
    f2.grid(column=1, row=0, sticky="n")
    root.rowconfigure(0, weight=1)
    
    Treeview(f1).pack(expand=True, fill='y')
    tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
    tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
    tk.Button(f2, text="DAT BUTTON IS IN F2").pack()
    
    root.mainloop()