Skip to content Skip to sidebar Skip to footer

Tkinter Resize Label Width (grid_propagate Not Working)

I'm having problem with adjusting the width of the label to reflect current width of the window. When the window size changes I'd like label to fill the rest of the width that is l

Solution 1:

It's not clear why you are using a label in a frame. I suspect this is an XY problem. You can get labels to consume extra space without resorting to putting labels inside frames. However, since you posted some very specific code with very specific questions, that's what I'll address.

Why label9 does not appear next to label8

Because you are creating the label as a child of the root window rather than a child of the frame. You need to create the label as a child of self inside PixelLabel:

classPixelLabel(...):
    def__init__(...):
        ...
        self.label = ttk.Label(self, ...)
        ...

How to make label9 resize to meet current window size (this code is just a sample, I would like to be able to resize label9 as the window size changes dynamically when functions are reshaping the window)

There are a couple more problems. First, you need to give column zero of the frame inside PixelFrame a non-zero weight so that it uses all available space (or, switch to pack).

classPixelLabel(...):
    def__init__(...):
        ...
        self.grid_columnconfigure(0, weight=1)
        ...

Second, you need to use the sticky attribute when placing nest_frame in the window so that it expands to fill its space:

nest_frame.grid(..., sticky="ew")

Post a Comment for "Tkinter Resize Label Width (grid_propagate Not Working)"