Search code examples
pythonuser-interfacetkintercustomtkinter

Responsive gui customtkinter


My GUI application is not responsive, I want it to resize according to the window size.

Currently am using .place(x,y) for placing components.

Example:

label.place(x=100,y=50)

Current components when windows maximized

Tried looking for a solution, and was informed of .pack() method for placing component, it has 2 paramas relative x (relx) and relative y (rely) in respect to its frame/master. Tested it out but still my GUI app isn't .responsive.


Solution

  • The .place(x, y) method always places a widget at the same spot.

    If you want it to change when the window is resized you should add this line to your code:

    root.bind("<Configure>", change_size)
    

    Where change_size is a function which can be used to modify the widgets placement / size to match the window's size.

    If you need the width and height of the window in the change_size function (you probably need those), this is the way to obtain them:

    width = win.winfo_width()
    height = win.winfo_height()
    

    Hope I helped you, have a nice day.