Python tkinter minimize or maximize the windows

Example of minimize or maximize the TK window in Python

Following code show the example of minimize or open the tk window as below:

tkWindow.state(newstate=’iconic’) is used for the minimize the window.

tkWindow.state(newstate=’normal’) is used for the maximize the window.

from tkinter import *
import time

#tkwindow in the 
tkWindow = Tk()  
tkWindow.geometry('500x500')  
tkWindow.title('Test the utility')



#set window background color
tkWindow.configure(bg='lightgray')

#Set the state newstate
def minimize1(): 
    #make the window minimize 
    tkWindow.state(newstate='iconic')
    time.sleep(3)
    # for make the window maximize or open
    tkWindow.state(newstate='normal')

Button1 = Button(tkWindow, text="Minimize", command=minimize1)
Button1.grid(row=2, column=6, padx=10, pady=20)  

tkWindow.mainloop()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.