Search code examples
python-3.xtkintercustomtkinter

customtkinter: How to dynamically resize Frame with window using place()


So I use place() instead of grid() or pack() because afaik, they all serve the same purpose if you know how to use one of them correctly. I have a 800x600 window with a 800x600 frame within it, when I resize the window the frame remains 800x600. What I want is the frame resizing itself (along with it's content) to the new window size but I don't how so thank you in advance!

Here is how I create and place my frame in the window:

bgFrame = customtk.CTkFrame(app, fg_color="white", width=800, height=600)
bgFrame.place(relx=0.5, rely=0.5, anchor="center")

Solution

  • If you want a widget (using .place() as the layout manager) to be resized when its parent is resized, then you need to set both relwidth and relheight options of .place(...) to 1:

    bgFrame.place(relx=0.5, rely=0.5, relwidth=1, relheight=1, anchor="center")