Home > database >  Cutomtkinter label packs at bottom of a window instead of packing into set frame
Cutomtkinter label packs at bottom of a window instead of packing into set frame

Time:01-12

I want to have a frame with labels inside the main application frame, but when I try to add a label to this frame the label is at bottom of the window instead. Code:

class Main(CTk):
    def __init__(self):
        super().__init__()
        self.geometry("750x500")
        self.maxsize(750,500)
        self.minsize(750,500)
        self.title("Program")
        title = CTkLabel(self, text="[TITLE PLACEHOLDER]", font=("ROBOTO",24))
        title.pack(pady=5, side=TOP)
        frame = CTkFrame(self)
        frame.pack(pady=15,padx=15,fill="both", expand=True)
        headerFrame = CTkFrame(frame).pack(padx=10,pady=5,fill="x",side=TOP)
        label = CTkLabel(headerFrame,text="LABEL").pack(side=TOP) #This label is at the bottom of the screen

if __name__ == "__main__":
    main = Main()
    main.mainloop()

Output: image of the output

I tried using another frame instead of a label, but still got same results.

CodePudding user response:

Thanks to the comments! I tried to separate creating and packing the frame and label and it works as it should! Working code:

headerFrame = CTkFrame(frame)
headerFrame.pack(padx=10,pady=5,fill="x",side=TOP)
label = CTkLabel(master=headerFrame,text="LABEL")
label.pack(side=TOP)

Output: output of the working code

  • Related