I tried making a Tree-Table in TKinter which is supposed to expand when I change the windows size. The original idea was from Tkinter, treeview doesn't resize ,from which I already copied some lines. However I need the tree to be accessible for later use, so I changed it to a variable. Does anyone know why it's not working anymore?
Heres the code, Thanks in advance!
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()
CodePudding user response:
To make a column or row stretchable, use rowconfigure
or columnconfigure
, and supply a value that gives the relative weight of this column or row when distributing the extra space.
A simple solution would be to just apply these on the root object, like so
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()
For more info see tkinter/grid-config