i tried to copy and paste the code from furas (i was looking for something like that): Vertical scrollbar for frame in Tkinter, Python
This code create: - a window with tkinter - a frame - and a vertical scrollbar
The only issue is that the frame does not fit to the root window. Can you please let me know how to fit the frame to the main window with that code (i changed few things in the code of the link, please find it below)?
no error messages are generated, but if you run it, you will see that the frame does not fit to the root window
Thank you for your help
import tkinter as tk
from tkinter import *
def on_configure(event):
# update scrollregion after starting 'mainloop'
# when all widgets are in canvas
canvas.configure(scrollregion=canvas.bbox('all'))
root = tk.Tk()
root.geometry("1200x1000")
# --- create canvas with scrollbar ---
canvas = tk.Canvas(root)
canvas.pack(side=tk.LEFT)
scrollbar = tk.Scrollbar(root, command=canvas.yview)
scrollbar.pack(side=tk.LEFT, fill='y')
canvas.configure(yscrollcommand = scrollbar.set)
# update scrollregion after starting 'mainloop'
# when all widgets are in canvas
canvas.bind('<Configure>', on_configure)
# --- put frame in canvas ---
frame = tk.Frame(master=root, width=980, height=980)
canvas.create_window((0,0), window=frame, anchor='nw')
#frame.pack_propagate(0) #Don't allow the widgets inside to determine the frame's width / height
#frame.pack(fill=tk.BOTH, expand=True) #Expand the frame to fill the root window
# --- add widgets in frame ---
l = tk.Label(frame, text="Hello", font="-size 50")
l.pack()
l = tk.Label(frame, text="World", font="-size 50")
l.pack()
l = tk.Label(frame, text="Test text 1\nTest text 2\nTest text 3\nTest text 4\nTest text 5\nTest text 6\nTest text 7\nTest text 8\nTest text 9", font="-size 20")
l.pack()
# --- start program ---
root.mainloop()