Tkinter Geometry Return to Normal Tkinter Geometry Return to Normal tkinter tkinter

Tkinter Geometry Return to Normal


Call the geometry with a value of "" to get it to reset itself to its natural size.

Tkinter is based on tk, and the tk docs say this on the matter:

If newGeometry is specified as an empty string then any existing user-specified geometry for window is cancelled, and the window will revert to the size requested internally by its widgets.


I believe you're looking for the winfo_reqwidth/reqheight() methods. These return the required width and height for all the widgets that are children of the widget they're called on. Just plug those into the geometry() method the same way you did to go fullscreen on your restore function, like this:

def fullscreen():    root.overrideredirect(True)    root.geometry('{0}x{1}+0+0'.format(root.winfo_screenwidth(), root.winfo_screenheight()))def restore():    root.overrideredirect(False)    root.geometry('{0}x{1}'.format(root.winfo_reqwidth(), root.winfo_reqheight()))root = Tk()Button(root, text='Full Screen', command=fullscreen).pack()Button(root, text='Restore', command=restore).pack()root.mainloop()