- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Showing and Hiding widgets in Tkinter?
Let us suppose that we have to create an application such that we can show as well as hide the widgets whenever we need.
The widgets can be hidden through pack_forget() method.
To show the hidden widgets, we can use the pack() method.
Both methods can be invoked using the lambda or anonymous function.
Example
#Import the required library from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("650x450") #Define function to hide the widget def hide_widget(widget): widget.pack_forget() #Define a function to show the widget def show_widget(widget): widget.pack() #Create an Label Widget label= Label(win, text= "Showing the Message", font= ('Helvetica bold', 14)) label.pack(pady=20) #Create a button Widget button_hide= Button(win, text= "Hide", command= lambda:hide_widget(label)) button_hide.pack(pady=20) button_show= Button(win, text= "Show", command= lambda:show_widget(label)) button_show.pack() win.mainloop()
Output
Running the above code will display a window with two buttons “Show” and “Hide” which can be used to show and hide the widgets.
Now click on “Hide” button to hide the Label Text and “Show” to show the Label Text.
- Related Articles
- Showing and hiding menu items in SAP HANA Studio Perspective
- How to show and hide widgets in Tkinter?
- Difference between .pack and .configure for widgets in Tkinter
- How to toggle between hiding and showing an element with JavaScript?
- Configure tkinter/ttk widgets with transparent backgrounds
- How to create transparent widgets using Tkinter?
- Hiding major tick labels while showing minor tick labels in Matplotlib
- How do you overlap widgets/frames in Python tkinter?
- How to capture events on Tkinter child widgets?
- How to delete Tkinter widgets from a window?
- What is the difference between the widgets of tkinter and tkinter.ttk in Python?
- Changing the Default Font for all the widgets in Tkinter
- Adding a scrollbar to a group of widgets in Tkinter
- How to set the border color of certain Tkinter widgets?
- How to add space between two widgets placed in a grid in tkinter?

Advertisements