Skip to content Skip to sidebar Skip to footer

Tkinter Scrollable And Expandable Panedwindow

I already searched a lot on Stackoverflow, and a lot of blogs, docs... And I don't find the way to make a 'PanedWindow' to be scrollable AND expand + fill. Check this example '''Te

Solution 1:

By default, the inner frame will expand or shrink to the optimal size for its contents. Since the contents of the frame aren't as wide as the canvas, the frame will not be as wide as the canvas.

If you want it to fill the canvas, you need to explicitly set the width to be the same as the width of the canvas whenever the canvas changes size.

First, let's make sure we can identify the inner frame by giving it a tag. You could just as easily capture the identifier returned by window_create.

canvas.create_window((0, 0), window=frame, anchor=CENTER, tags=("inner_frame",))

Next, add a binding to call a function whenever the canvas configuration changes.

canvas.bind("<Configure>", self.resize_inner_frame)

Finally, define the resize function. On <Configure> events, the event object will contain a width parameter which represents the width of the object. We can use this to determine the width of the inner frame.

defresize_inner_frame(self, event):
    self.canvas.itemconfigure("inner_frame", width=event.width)

You might need to adjust the width to accommodate canvas borders.

Post a Comment for "Tkinter Scrollable And Expandable Panedwindow"