Python中的turtle.clearstamp()方法
turtle模块以面向对象和面向过程的方式提供Turtle图形基元。因为它使用 Tkinter 作为底层图形,它需要安装一个支持 Tk 的 Python 版本。
turtle.clearstamp()
turtle.clearstamp()方法用于删除turtle的全部或前/后n个邮票。这个方法需要一个整数的参数。所以,用一个id做的印章会被它清除掉。
语法: turtle.clearstamp(stampid)
参数:
stampid – 一个整数,必须是之前调用stamp()的返回值。
下面是上述方法的实现和一些例子。
例子1 :
# import package
import turtle
# set turtle speed to slowest
# for better understandings
turtle.speed(1)
# motion with stamps
# and their ids
turtle.forward(50)
id1 = turtle.stamp()
turtle.forward(50)
id2 = turtle.stamp()
turtle.forward(50)
id3 = turtle.stamp()
# hide the turtle to
# clarify stamps
turtle.ht()
# clear the stamps
# of id : id1 and id3
turtle.clearstamp(id1)
turtle.clearstamp(id3)
输出 :
例子2 :
# import package
import turtle
# list to store ids
ids = []
# loop to create motion
# with stamps
for i in range(12):
# motion
turtle.forward(50)
# stampid
id = turtle.stamp()
lst.append(id)
turtle.right(30)
# hide the turtle for
# better understandings
turtle.ht()
# loop for clear stamps with
# their ids using clearstamp
# half stamps are cleared
for i in range(len(lst)//2):
turtle.clearstamp(lst[i])
输出 :