- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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
How to hide a widget after some time in Python Tkinter?
Tkinter is a standard Python library for developing GUI-based applications. We can create games, tools, and other applications using the Tkinter library. To develop GUI-based applications, Tkinter provides widgets.
Sometimes, there might be a requirement to hide a widget for some time. This can be achieved by using the pack_forget() method. When we pack the widget in the window using the various methods, we have to use the same method for hiding the widget.
# Import the required libraries from tkinter import * from PIL import Image, ImageTk # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") # Create a canvas widget canvas=Canvas(win, width=400, height=300) canvas.pack() # Add an image in the canvas widget img=ImageTk.PhotoImage(file="baseball.png") canvas.create_image(100, 150,image=img) # Hide the image from the canvas after sometime canvas.after(3000, canvas.pack_forget) win.mainloop()
Running the given code will display an image in the Canvas widget that will disappear after sometime.
- How to update a Python/tkinter label widget?
- How to clear the Entry widget after a button is pressed in Tkinter?
- How to insert the current time in an Entry Widget in Tkinter?
- Progressbar widget in Python Tkinter
- How to center a Tkinter widget?
- Python Tkinter – How to display a table editor in a text widget?
- How to update a Button widget in Tkinter?
- How do I give focus to a python Tkinter text widget?
- How to make a Tkinter widget invisible?
- How to see if a widget exists in Tkinter?
- How to create hyperlink in a Tkinter Text widget?
- How to highlight text in a tkinter Text widget?
- How to remove focus from a Tkinter widget?
- How to center a Tkinter widget in a sticky frame?
- Python Tkinter – How to position a topLevel() widget relative to the root window?