Tkinter,treeview不会调整大小

Van*_*ush 1 treeview tkinter python-3.x

当我调整窗口高度时,如何调整树视图大小?我尝试设置sticky="sn",我试图打包树视图fill='y',但没有任何效果.

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()
Run Code Online (Sandbox Code Playgroud)

fur*_*ras 7

你需要sticky="ns"重新调整Frame窗口,并fill='y', expand=True调整大小TreeviewFrame

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()
Run Code Online (Sandbox Code Playgroud)