Skip to content Skip to sidebar Skip to footer

Manually Inserting Into Frame Sets Scrollbar To Not Work Tkinter

I have a code with scrollbar that works correctly, if the widgets are inserted onto the frame during automatically(during runtime?). But once I add widgets by pressing a button, it

Solution 1:

This event is never been fired:

my_canvas.bind('<Configure>', lambda e: my_canvas.configure(scrollregion = my_canvas.bbox("all")))

The reason is fairly easy when you know that your function adds buttons to second_frame and thats why second_frame will be configured in width and height.

so you need this line after defining the second_frame:

second_frame.bind('<Configure>', lambda e: my_canvas.configure(scrollregion = my_canvas.bbox("all")))

Solution 2:

You only configure the scrollregion when the canvas changes size (or more specifically, when the <Configure> event is triggered on the canvas).

When you add buttons to the inner frame, that won't cause the canvas to change size. Instead, you need to either bind to the <Configure> event on the inner frame, or explicitly reconfigure the scrollregion after adding the button.

def more():
    tk.Button(second_frame,text='MORE').pack()
    my_canvas.configure(scrollregion=my_canvas.bbox("all"))

Post a Comment for "Manually Inserting Into Frame Sets Scrollbar To Not Work Tkinter"