在 Python Tkinter 中调整树的大小
Resizing Tree in Python Tkinter
我尝试在 TKinter 中制作一个 Tree-Table,它应该在我更改 windows 大小时扩展。最初的想法来自 ,我已经从中复制了一些行。但是我需要树可以访问以供以后使用,所以我将它更改为一个变量。有谁知道为什么它不再工作了?
这是代码,在此先感谢!
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()
要使列或行可伸缩,请使用 rowconfigure
或 columnconfigure
,并提供一个值,在分配额外的 space 时给出此列或行的相对权重。
一个简单的解决方案是将它们应用到根对象上,就像这样
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
我尝试在 TKinter 中制作一个 Tree-Table,它应该在我更改 windows 大小时扩展。最初的想法来自
这是代码,在此先感谢!
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()
要使列或行可伸缩,请使用 rowconfigure
或 columnconfigure
,并提供一个值,在分配额外的 space 时给出此列或行的相对权重。
一个简单的解决方案是将它们应用到根对象上,就像这样
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