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
from tkinter import *
root = Tk()
root.title( "Main Window" )
root.geometry( "200x200" )
def launch():
global second
second = Toplevel()
second.title( "Child Window" )
second.geometry( "400x400" )
def show():
second.deiconify()
def hide():
second.withdraw()
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 )
root.mainloop()
|
Output:
Last Updated :
04 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...