Search code examples
pythontkinterttk

Is there a way to resize the children widgets when the parent widget is maximized in tkinter


I'm currently working on this project and was wondering is there a way to resize all the children widgets present inside the parent widget when the user maximize the parent widget root, I know about .grid_rowconfigure()and .grid_columnconfigure(), but using these methods isn't changing the fontsize/actual size of my widgets. I would like to know if there's a way to bind the maximize button present on the top right conner of the parent widget.

Thank you.


Solution

  • This question has been answered here. The solution: First of all, we need to bind the window to the <Configure> event. The <Configure> event gets triggered whenever a window event occurs.

    window.bind("<Configure>", is_maximized)
    

    Now, when the event gets triggered, the is_maximized function will be called:

    def is_maximized(event):
        if window.state() == "zoomed":
            # your code
    

    In the function, we are checking if the window state is equal to zoomed. If so, it means that the window is maximized. Now, you can just add whatever code you need inside the if clause.