Open In App

Hide and Unhide The Window in Tkinter – Python

Prerequisite: Tkinter

Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using Tkinter is an easy task.



In this article, we will discuss how to hide and unhide the window in Tkinter Using Python.

Functions used:



Syntax:

toplevel = Toplevel(root, bg, fg, bd, height, width, font, ..)

Syntax:

deiconify()

Syntax:

withdraw()

Approach:

Program:




# Import Library
from tkinter import *
 
# Create Object
root = Tk()
 
# Set title
root.title("Main Window")
 
# Set Geometry
root.geometry("200x200")
 
# Open New Window
def launch():
    global second
    second = Toplevel()
    second.title("Child Window")
    second.geometry("400x400")
 
# Show the window
def show():
    second.deiconify()
 
# Hide the window
def hide():
    second.withdraw()
 
# Add Buttons
Button(root, text="launch Window", command=launch).pack(pady=10)
Button(root, text="Show", command=show).pack(pady=10)
Button(root, text="Hide", command=hide).pack(pady=10)
 
# Execute Tkinter
root.mainloop()

Output:

Article Tags :