Open In App

turtle.clearstamps() method in Python

Last Updated : 21 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.

turtle.clearstamps()

The turtle.clearstamps() method is used to delete all or first/last n of turtle’s stamps. This method requires an argument of an integer. So, the n stamps made are cleared by it.

Syntax : turtle.clearstamps(n=None)

Optional argument: n — an integer

  • If n is None, delete all of pen’s stamps,
  • else if n > 0 delete first n stamps
  • else if n < 0 delete last n stamps.

Below is the implementation of the above method with some examples :

Example 1 :

Python3




# import package
import turtle 
  
  
# set turtle speed to slowest 
# for better understandings
turtle.speed(1)
  
# motion with stamps
turtle.forward(50)
turtle.stamp()
turtle.forward(50)
turtle.stamp()
turtle.forward(50)
turtle.stamp()
  
# hide the turtle to
# clarify stamps
turtle.ht()
  
# clear the all stamps
turtle.clearstamps()


Output :

Example 2 :

Python3




# import package
import turtle 
  
  
# loop to create motion
# with stamps
for i in range(12):
      
    # motion
    turtle.forward(50)
      
    # stamp
    turtle.stamp()
    turtle.right(30)
  
# hide the turtle for 
# better understandings
turtle.ht()
  
# clear the first 8 stamps
turtle.clearstamps(8)


Output :



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads