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:

turtle.clearstamp() function in Python

In the above code, we followed the below steps:

  1. Import the module: import turtle loads Python’s turtle graphics library.
  2. Create the screen: window = turtle.Screen() opens the drawing window.
  3. Create the turtle: t = turtle.Turtle() creates the turtle you’ll control.
  4. 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.
  5. Move forward: t.forward(100) draws a 100-unit line in the current heading.
  6. Clear specific stamp: t.clearstamp(stamp_id) removes only the stamped imprint that matches the saved ID; the turtle and any drawn lines remain.
  7. 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:

turtle.stamp() function in Python
turtle.towards() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment