- 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 clear Tkinter Canvas?
Tkinter provides a way to add a canvas in a window and when we create a canvas, it wraps up some storage inside the memory. While creating a canvas in tkinter, it will effectively eat some memory which needs to be cleared or deleted.
In order to clear a canvas, we can use the delete() method. By specifying “all”, we can delete and clear all the canvas that are present in a tkinter frame.
#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("650x250") #Creating a canvas myCanvas =Canvas(win, bg="white", height=200, width=200) cordinates= 10, 10, 200, 200 arc = myCanvas.create_arc(cordinates, start=0, extent=320, fill="red") myCanvas.pack() #Clearing the canvas myCanvas.delete('all') win.mainloop()
The above code will clear the canvas,
First, mark the following line as a comment and execute the code.
It will produce the following window:
Now, uncomment the line and execute again to clear the canvas.
- How to clear a Tkinter ListBox?
- How to reconfigure Tkinter canvas items?
- How to clear an entire Treeview with Tkinter?
- How to bind events to Tkinter Canvas items?
- How to clear out a frame in the Tkinter?
- How to add text inside a Tkinter Canvas?
- How to make a Tkinter canvas rectangle transparent?
- How to move a Tkinter canvas with Mouse?
- How to clear the contents of a Tkinter Text widget?
- Moving balls in Tkinter Canvas
- How to center an image in canvas Python Tkinter
- How to update an image in a Tkinter Canvas?
- How to create a Button on a Tkinter Canvas?
- How to open PIL Image in Tkinter on Canvas?
- How to get coordinates on scrollable canvas in Tkinter?