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:
- Toplevel() is used to launch the second window
Syntax:
toplevel = Toplevel(root, bg, fg, bd, height, width, font, ..)
- deiconify() is used to show or unhide the window
Syntax:
deiconify()
- withdraw() is used to hide the window
Syntax:
withdraw()
Approach:
- Import module
- Create a normal window
- Add buttons to perform hide and unhide actions
- Now create one more window
- Execute code
Program:
Python3
# Import Libraryfrom tkinter import *# Create Objectroot = Tk()# Set titleroot.title("Main Window")# Set Geometryroot.geometry("200x200")# Open New Windowdef launch(): global second second = Toplevel() second.title("Child Window") second.geometry("400x400")# Show the windowdef show(): second.deiconify()# Hide the windowdef hide(): second.withdraw()# Add ButtonsButton(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 Tkinterroot.mainloop() |
Output:




