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

# Define the style for combobox widget
style = ttk.Style()

# Define a function to show/hide widget
def show_widget():
def hide_widget():
   b1.configure(text="Show", command=show_widget)

# Add a label widget
label = ttk.Label(win, text="Eat, Sleep, Code and Repeat", font=('Aerial 11'))

# Add a Button widget
b1 = ttk.Button(win, text="Hide", command=hide_widget)



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.