Skip to content
Related Articles

Related Articles

Hide and Unhide The Window in Tkinter – Python

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 04 Jul, 2021
View Discussion
Improve Article
Save Article

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 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:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!