How to control automated window resizing in Tkinter?

TkinterServer Side ProgrammingProgramming

The Tkinter window can be resized manually by defining the geometry ("width × height") method. We can automate or reset the window to its original form by passing an empty value to the geometry manager. Once the empty value is passed to the method, it will get resized automatically. In this example, we will create a Tkinter application that will display a Toplevel window (Popup window) with a defined size. When we press a RESET button, it will be resized again to its default size.


#Import the library
from tkinter import *
from tkinter import ttk

#Create an instance of tkinter frame
win= Tk()

#Set the window geometry

#Create a Label
Label(win, text= "Tkinter is a GUI Library in Python", font=('Helvetica 15 bold')).pack(pady=20)

#Define a function to reset the window size
def reset_win():

#Create a Button to Hide/ Reveal the Main Window
button= ttk.Button(win, text="RESET" ,command= reset_win)



Running the above code will display a window that contains a button. Once we click the RESET Button it will get resized to its default size which prevents the window to be resized manually.

Now, click the Button to reset the size of the Main window that will automatically get resized to its default size.

Updated on 04-May-2021 14:17:33