I was trying to get the scrollbar to work, in my tkinter application with this previous post: Adding a scrollbar to a group of widgets in Tkinter.
Everything is working fine if I uncomment out the code before the for loop, but to my (limited) understanding, I believe that it should also work if I uncomment out the code inside of the for loop instead.
As I understand it, calling canvas.configure(scrollregion=canvas.bbox("all"))
should update the scrollregion of the canvas to include all of the label widgets that are placed inside of the frame. The first one just does it automatically every time a new label widget gets added into the frame with frame.bind("<Configure>",onFrameConfigure)
while the second does it manually, so what's the difference? Why doesn't it work?
import tkinter
root = tkinter.Tk()
canvas = tkinter.Canvas(root)
frame = tkinter.Frame(canvas)
scrollbar=tkinter.Scrollbar(root,orient="vertical",command=canvas.yview)
canvas.configure(yscrollcommand=scrollbar.set)
scrollbar.pack(side="right", fill="y")
canvas.pack(fill="both", expand=True)
canvas.create_window((0, 0), window=frame, anchor="nw")
# works
#def onFrameConfigure(event):
# canvas.configure(scrollregion=canvas.bbox("all"))
#
#frame.bind("<Configure>", onFrameConfigure)
for x in range(100):
new_label = tkinter.Label(frame, text="%d"%x)
new_label.pack()
# doesn't work
#canvas.configure(scrollregion=canvas.bbox("all"))
root.mainloop()