18 Sep turtle.clearstamp() function in Python
The turtle.clearstamp() function in Python deletes a specific stamp from the canvas, making it invisible.
Syntax: turtle.clearstamp(stampid)
Parameters: stampid – an integer returned by a previous stamp() call.
Let us see an example to implement the turtle.clearstamp() function in Python:
Demo13.py
# turtle.clearstamp() function in Python # Code by Studyopedia import turtle window = turtle.Screen() t = turtle.Turtle() stamp_id = t.stamp() # Stamp and save the stamp ID t.forward(100) t.clearstamp(stamp_id) # Remove the stamp with the given ID 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 you’ll control.
- Stamp and save ID: stamp_id = t.stamp() leaves an imprint of the turtle’s current shape at its position and returns a unique ID for that imprint.
- Move forward: t.forward(100) draws a 100-unit line in the current heading.
- Clear specific stamp: t.clearstamp(stamp_id) removes only the stamped imprint that matches the saved ID; the turtle and any drawn lines remain.
- Close on click: window.exitonclick() keeps the window open until you click inside it, 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