ich hab mir aus dem netz folgenden code gemopst, um zu verstehen, wie ich die höhe von irgendwas innerhalb eines
canvas-frames an dessen containerhöhe anpassen kann.
da hängt es leider schon etwas länger
den code bis hier her habe ich denke ich verstanden.
warum gelingt die höhenanpassung nicht einmal manuell???
Code: Alles auswählen
import tkinter as tk
from tkinter import ttk
class ScrollFrame(tk.Frame):
def __init__(self, parent, xscroll=True):
tk.Frame.__init__(self, parent)
canvas = tk.Canvas(self, bd=0, highlightthickness=0)
if xscroll:
hscrollbar = tk.Scrollbar(self, orient=tk.HORIZONTAL)
hscrollbar.pack(fill=tk.X, side=tk.BOTTOM, expand=tk.FALSE)
canvas.config(xscrollcommand=hscrollbar.set)
hscrollbar.config(command=canvas.xview)
canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.TRUE)
canvas.xview_moveto(0)
canvas.yview_moveto(0)
self.interior = tk.Frame(canvas, bg="blue")
self.interior_id = canvas.create_window(0, 0, window=self.interior, anchor=tk.NW)
def _configure_interior(_):
canvas.config(scrollregion=canvas.bbox('all'))
self.interior.bind('<Configure>', _configure_interior)
root = tk.Tk()
root.geometry("582x450")
frame = tk.Frame(root)
frame.pack(fill=tk.BOTH, expand=True)
sf = ScrollFrame(frame)
sf.pack(fill=tk.BOTH, expand=True)
sf.interior.config()
canvas = tk.Canvas(sf.interior)
canvas.pack(fill=tk.BOTH, expand=True)
test = tk.Frame(canvas)
test.pack(fill=tk.BOTH, expand=True)
table = ttk.Treeview(test, columns='header', show='headings')
# table.heading("#0", text="#0", anchor=W)
# table.column("#0", width=100, anchor='nw')
table.heading("header", text="Header", anchor=tk.W)
table.column("header", width=500, anchor='nw')
table.insert("", "end", text="Grace", values=("2010-09-23", "03:44:53", "Garden"))
table.insert("", "end", text="John", values=("2017-02-05", "11:30:23", "Airport"))
table.insert("", "end", text="Betty", values=("2014-06-25", "18:00:00", ""))
#root.update()
frame.update()
#sf.interior.update()
#canvas.update()
#test.update()
#table.update()
# print("root: " + str(root.winfo_height()), str(root.winfo_reqheight()))
print("frame: " + str(frame.winfo_height()), str(frame.winfo_reqheight()))
# print("sf.interior: " + str(sf.interior.winfo_height()), str(sf.interior.winfo_reqheight()))
# print("canvas: " + str(canvas.winfo_height()), str(canvas.winfo_reqheight()))
# print("test: " + str(test.winfo_height()), str(test.winfo_reqheight()))
# print("table: " + str(table.winfo_height()), str(table.winfo_reqheight()))
# table.configure(height=frame.winfo_height())
table.configure(height=350)
table.pack()
root.mainloop()