我嘗試在 TKinter 中制作一個樹表,當我更改視窗大小時它應該會擴展。最初的想法來自Tkinter,treeview 不會調整大小,我已經從中復制了一些行。但是我需要樹可以訪問以供以后使用,所以我將它更改為一個變數。有誰知道為什么它不再作業了?
這是代碼,在此先感謝!
from tkinter.ttk import Treeview
root = tk.Tk()
headlines = ["H1","H2","H3","H4","H5","H6","H7","H8"]
f1 = tk.Frame(root)
f1.grid(column=0,row=0,sticky="ns")
tree =Treeview(f1,show = ["headings"])
tree['columns'] = headlines
#naming Headlines
for i in headlines:
tree.heading(i,text=i)
tree.pack(expand=True,fill='y')
root.mainloop()
uj5u.com熱心網友回復:
要使列或行可伸縮,請使用rowconfigure或columnconfigure,并提供一個值,該值在分配額外空間時給出該列或行的相對權重。
一個簡單的解決方案是將這些應用到根物件上,就像這樣
from tkinter.ttk import Treeview
import tkinter as tk
root = tk.Tk()
headlines = ["H1", "H2", "H3", "H4", "H5", "H6", "H7", "H8"]
f1 = tk.Frame(root)
f1.grid(column=0, row=0, sticky="ns")
tree = Treeview(f1, show=["headings"])
tree['columns'] = headlines
# naming Headlines
for i in headlines:
tree.heading(i, text=i)
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
tree.pack(expand=True, fill='y')
root.mainloop()
有關更多資訊,請參閱tkinter/grid-config
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/430790.html
