Python中的 turtle.clearstamps() 方法
turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。
海龟.clearstamps()
turtle.clearstamps() 方法用于删除所有或第一个/最后 n 个海龟的图章。此方法需要一个整数参数。因此,制作的 n 个邮票被它清除。
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.
以下是上述方法的实现以及一些示例:
示例 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()
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)
输出 :
示例 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)
输出 :