Python 3.8.5 on Windows 10, Tkinter
I would like to place different frames (each of them contain texts) in a bigger frame (the main frame), and allow to scroll the main frame in order to see all the frames inside. So I place the main frame in a canvas, and I use the scrollbar to scroll the canvas which contains the main frame. However, the scrollbar doesn't work, nothing happen when I use it, and I have no access to all the frames inside the main frame.
The second thing I don't understand is that I use frame.pack_propagate(False) to avoid that all the frames inside the main frame automatically resize to their content, but they do it anyway. Why ?
Thanks for the help !
from tkinter import *
def on_configure(event):canvas.configure(scrollregion=canvas.bbox("all"))
def accueil():
global canvas
canvas=Canvas(root)
scrollbar=Scrollbar(root,command=canvas.yview)
canvas.configure(yscrollcommand=scrollbar.set)
canvas.bind("<Configure>",on_configure)
frame=Frame(canvas,bg="orange",width=canvas.winfo_reqwidth(),height=canvas.winfo_reqheight())
canvas.create_window((0,0),window=frame)
frame_nouveaute_1=Frame(frame,bg="red",width=300,height=150)
frame_nouveaute_1.pack_propagate(False)
frame_nouveaute_1.place(y=0)
l=Label(frame_nouveaute_1,text="- Nouveauté 1",font=25,bg="red").grid(row=0)
l=Label(frame_nouveaute_1,text=" . xxxxx",font=25,bg="red").grid(row=1)
l=Label(frame_nouveaute_1,text=" . yyyyy",font=25,bg="red").grid(row=2)
l=Label(frame_nouveaute_1,text=" . zzzzz",font=25,bg="red").grid(row=3)
frame_nouveaute_2=Frame(frame,bg="green",width=300,height=150)
frame_nouveaute_2.pack_propagate(False)
frame_nouveaute_2.place(y=frame_nouveaute_1.winfo_reqheight()+10)
l=Label(frame_nouveaute_2,text="- Nouveauté 2",font=25,bg="green").grid(row=0)
l=Label(frame_nouveaute_2,text=" . xxxxx",font=25,bg="green").grid(row=1)
l=Label(frame_nouveaute_2,text=" . yyyyy",font=25,bg="green").grid(row=2)
l=Label(frame_nouveaute_2,text=" . zzzzz",font=25,bg="green").grid(row=3)
frame_nouveaute_3=Frame(frame,bg="blue",width=300,height=150)
frame_nouveaute_3.pack_propagate(False)
frame_nouveaute_3.place(y=frame_nouveaute_1.winfo_reqheight()+10+frame_nouveaute_2.winfo_reqheight()+10)
l=Label(frame_nouveaute_3,text="- Nouveauté 3",font=25,bg="blue").grid(row=0)
l=Label(frame_nouveaute_3,text=" . xxxxx",font=25,bg="blue").grid(row=1)
l=Label(frame_nouveaute_3,text=" . yyyyy",font=25,bg="blue").grid(row=2)
l=Label(frame_nouveaute_3,text=" . zzzzz",font=25,bg="blue").grid(row=3)
canvas.place(y=25)
scrollbar.pack(side="right",fill="y")
root=Tk()
root.geometry("%dx%d+%d+%d"%(500,350,10,10))
accueil()
root.mainloop()