Skip to content

Why are the grids different? #2771

@svenakela

Description

@svenakela

I have this code in a class that generates a frame for each mp3 file in a list. These frames are added to a scrollable frame.


class Playable(CTkFrame):
    def __init__(self, master:any, controller:UiController, pm:PlayableMeta):
        super().__init__(master)
        self.pm = pm
        self.controller = controller
        self.grid_rowconfigure((0, 1), weight=1)
        self.columnconfigure(index=0, weight=1)
        self.columnconfigure(index=1, weight=5)
        self.columnconfigure(index=2, weight=1)

        self.lbl_title = CTkLabel(self,
                                 text=pm.title,
                                 font=("Arial", 28), anchor="nw")
        self.lbl_artist = CTkLabel(self,
                                 text=pm.artist,
                                 font=("Arial", 16), anchor="nw")
        self.lbl_length = CTkLabel(self,
                                 text="00:00.000",
                                 font=("Arial", 16), bg_color="#228B22", anchor="e", padx=5, pady=5)
        self.lbl_start  = CTkLabel(self,
                                 text="00:00.000",
                                 font=("Arial", 16), bg_color="#444", text_color="#999", anchor="e", padx=5, pady=5)

        if pm.start > 0:
            self.lbl_start.configure(bg_color="#FF6347", text_color="white")

        PositionStuff.full_sticky_mid_pad(self.lbl_title,  row=0, col=1 )
        PositionStuff.full_sticky_mid_pad(self.lbl_artist, row=1, col=1)
        PositionStuff.full_sticky_mid_pad(self.lbl_length, row=0, col=2 )
        PositionStuff.full_sticky_mid_pad(self.lbl_start,  row=1, col=2 )


class PositionStuff:

    @staticmethod
    def full_sticky(panel, row=0, col=0):
        return panel.grid(row=row, column=col, sticky="nsew", padx=10, pady=10)

    @staticmethod
    def full_sticky_mid_pad(panel, row=0, col=0):
        return panel.grid(row=row, column=col, sticky="nsew", padx=5, pady=5)

    @staticmethod
    def full_sticky_no_pad(panel, row=0, col=0):
        return panel.grid(row=row, column=col, sticky="nsew")

When I run this code with an example of two mp3 files, the labels and titles are rendered in different positions:

Image

In the bottom frame the title is shifted to the left and the labels are shorter.
I am confused, as of why?
The text is more or less the same length.

If I add the hint I've found on the Internettz:

self.grid_propagate(False)

This happens:

Image

...which is absolutely not want I expected.
Is there a way to enforce the grid to be "fixed" in width and height?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions