- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 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.
Example
#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,
Output
First, mark the following line as a comment and execute the code.
myCanvas.delete('all')
It will produce the following window:
Now, uncomment the line and execute again to clear the canvas.
- Related Articles
- How to Clear the Canvas for Redrawing?
- 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 make a Tkinter canvas rectangle transparent?
- How to move a Tkinter canvas with Mouse?
- How to add text inside a Tkinter Canvas?
- How to clear the contents of a Tkinter Text widget?
- How to center an image in canvas Python Tkinter
- How to get coordinates on scrollable canvas in Tkinter?
- How to hide and show canvas items on Tkinter?
- How to create a Button on a Tkinter Canvas?
- How to open PIL Image in Tkinter on Canvas?

Advertisements