- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to show and hide widgets in Tkinter?
Tkinter is a Python library which is used to create and develop GUI-based applications.Let us suppose that we have to create an application such that we can show or hide the widgets.
- In order to display/show the widget, use pack() geometry manager
- To hide any widget from the application, use pack_forget() method.
Let us take this example to understand how to show/hide widgets −
# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() # Set the size of the tkinter window win.geometry("700x350") # Define the style for combobox widget style = ttk.Style() style.theme_use('xpnative') # Define a function to show/hide widget def show_widget(): label.pack() def hide_widget(): label.pack_forget() b1.configure(text="Show", command=show_widget) # Add a label widget label = ttk.Label(win, text="Eat, Sleep, Code and Repeat", font=('Aerial 11')) label.pack(pady=30) # Add a Button widget b1 = ttk.Button(win, text="Hide", command=hide_widget) b1.pack(pady=20) win.mainloop()
Running the above code will open a window that will have a Button to show/hide the widgets from the application.
Now, click the button to display/hide the label text from the window.
- How to hide and show canvas items on Tkinter?
- Showing and Hiding widgets in Tkinter?
- How to create transparent widgets using Tkinter?
- How animate(), hide and show elements using jQuery?
- How to delete Tkinter widgets from a window?
- How to capture events on Tkinter child widgets?
- Difference between .pack and .configure for widgets in Tkinter
- How do you overlap widgets/frames in Python tkinter?
- How to set the border color of certain Tkinter widgets?
- How to show webcam in TkInter Window?
- How can I show and hide an HTML element using jQuery?
- Configure tkinter/ttk widgets with transparent backgrounds
- How to hide and show a column of a row in SAP Detail window
- Adding a scrollbar to a group of widgets in Tkinter