19 Sep turtle.clear() function in Python
The turtle.clear() function clears the drawing from the screen. This does not move the turtle or change its state (position, heading, etc.).
Syntax: turtle.clear()
Parameters: None.
Let us see an example to implement the turtle.clear() function in Python:
Demo30.py
# turtle.clear() function in Python
# Code by Studyopedia
import turtle
window = turtle.Screen()
t = turtle.Turtle()
# Draw some shapes
for i in range(5):
t.forward(50)
t.left(90)
t.clear() # Clear the turtle's drawings
window.exitonclick()
The following is the output:

In the above code, we followed the below steps:
- Import the module: import turtle loads Python’s turtle graphics library.
- Create the screen: window = turtle.Screen() opens the drawing window.
- Create the turtle: t = turtle.Turtle() creates the turtle (your pen).
- Draw with a loop:
- Repeat 5 times: for i in range(5):
- Move: t.forward(50) draws a 50-unit line.
- Turn: t.left(90) rotates 90° counterclockwise. This creates a sequence of right-angled segments.
- Clear drawings: t.clear() erases everything this turtle has drawn (including its stamps) from the screen but does not move the turtle or change its heading or pen settings.
- Close on click: window.exitonclick() keeps the window open until you click, then closes.
If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.
For Videos, Join Our YouTube Channel: Join Now
Read More:
- OpenCV Tutorial
- Python Tutorial
- NumPy Tutorial
- Pandas Tutorial
- Matplotlib Tutorial
- Generative AI Tutorial
- LangChain Tutorial
- RAG Tutorial
- Machine Learning Tutorial
- Deep Learning Tutorial
- Ollama Tutorial
- Retrieval Augmented Generation (RAG) Tutorial
- Copilot Tutorial
- Gemini Tutorial
- ChatGPT Tutorial
No Comments