Open In App

How to temporarily remove a Tkinter widget without using just .place?

Last Updated : 22 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will cover how to temporarily remove a Tkinter widget without using just .place

We can temporarily remove a Tkinter widget by calling the remove_widget() method to make the widgets temporarily invisible. We need to call the place_forget() method, it will hide or forget a widget from the parent widget screen in Tkinter.

Syntax: widget.place_forget() 

Parameter: None
Return: None

Stepwise Implementation

Step 1: Import the library.

from tkinter import *

Step 2: Create a GUI app using Tkinter.

app=Tk()

Step 3: Give a title and dimensions to the app.

app.title(“Title you want to assign to app”)
app.geometry("Dimensions of the app")

Step 4: Make a function to remove a Tkinter widget when the function is called.

def remove_widget():
 label.place_forget()

Step 5: Create a widget that needs to be removed on a particular instance.

label=Label(app, text=”Tkinter Widget”, font=’#Text-Font #Text-Size bold’)

label.place(relx=#Horizontal Offset, rely=#Vertical Offset, anchor=CENTER)

Step 6: Create a button to remove the widget.

button=Button(app, text=”Remove Widget”, command=remove_widget)

button.place(relx=#Horizontal Offset, rely=#Vertical Offset, anchor=CENTER)

Step 7:  At last, call an infinite loop for displaying the app on the screen.

app.mainloop()

Below is the Implementation

Python3




# Python program to temporarily remove a
# Tkinter widget without using just place
  
# Import the Tkinter library
from tkinter import *
  
# Create a GUI app
app=Tk()
  
# Set the title and geometry of the window
app.title('Remove Tkinter Widget')
app.geometry("600x400")
  
# Make a function to remove the widget
def remove_widget():
   label.place_forget()
  
# Create a label widget to display text
label=Label(app, text="Tkinter Widget", font='Helvetica 20 bold')
label.place(relx=0.5, rely=0.3, anchor=CENTER)
  
# Create a button to remove text
button=Button(app, text="Remove Widget", command=remove_widget)
button.place(relx=0.5, rely=0.7, anchor=CENTER)
  
# Make infinite loop for displaying app 
# on the screen
app.mainloop()


Output:

 


Previous Article
Next Article

Similar Reads

Python | place() method in Tkinter
The Place geometry manager is the simplest of the three general geometry managers provided in Tkinter. It allows you explicitly set the position and size of a window, either in absolute terms, or relative to another window. You can access the place manager through the place() method which is available for all standard widgets. It is usually not a g
3 min read
How to place a button at any position in Tkinter?
Prerequisite: Creating a button in Tkinter Tkinter is the most commonly used library for developing GUI (Graphical User Interface) in Python. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most com
2 min read
How To Place An Image Into A Frame In Tkinter?
In this article, we will walk through the process of placing an image into a frame in Tkinter. We will cover everything from setting up your environment to loading and displaying images using the PIL (Python Imaging Library) module, specifically Pillow. By the end of this tutorial, you will have a solid understanding of how to manage and display im
5 min read
Tkinter | Adding style to the input text using ttk.Entry widget
Tkinter is a GUI (Graphical User Interface) module which is widely used to create GUI applications. It comes along with the Python itself. Entry widgets are used to get the entry from the user. It can be created as follows- entry = ttk.Entry(master, option = value, ...) Code #1: Creating Entry widget and taking input from user (taking only String d
2 min read
Horizontally Center a Widget using Tkinter
Horizontally centering a widget in Tkintercan be achieved using the pack, grid, or place geometry managers, each providing different levels of control and flexibility. The method you choose depends on the specific requirements and complexity of your user interface. By using these techniques, you can ensure that your widgets are well-positioned and
4 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
Python | Menu widget in Tkinter
Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used package for GUI applications which comes with the Python itself. Menus are the important part of any GUI. A common use of menus is to provide convenient access to various operations such as saving or opening a file, quitting a program, or manipu
2 min read
Progressbar widget in Tkinter | Python
The purpose of this widget is to reassure the user that something is happening. It can operate in one of two modes - In determinate mode, the widget shows an indicator that moves from beginning to end under program control. In indeterminate mode, the widget is animated so the user will believe that something is in progress. In this mode, the indica
2 min read
Python | PanedWindow Widget in Tkinter
Tkinter supports a variety of widgets to make GUI more and more attractive and functional. The PanedWindow widget is a geometry manager widget, which can contain one or more child widgets panes. The child widgets can be resized by the user, by moving separator lines sashes using the mouse. Syntax: PanedWindow(master, **options) Parameters: master:
3 min read
How to change background color of Tkinter OptionMenu widget?
Prerequisites: Tkinter While creating GUI applications, there occur various instances in which you need to make selections among various options available. For making such choices, the Option Menu widget was introduced. In this article, we will be discussing the procedure of changing menu background color of Tkinter’s option Menu widget. To achieve
2 min read
Practice Tags :