python clear用法_Python turtle.clearstamp()用法及代码示例

turtle 模块以面向对象和面向过程的方式提供 turtle 图形基元。由于它使用Tkinter作为基础图形,因此需要安装有Tk支持的Python版本。

turtle .clearstamp()

turtle.clearstamp()方法用于删除所有或全部前n个邮票。此方法需要一个整数参数。因此,带有id的印章将被清除。

用法:turtle.clearstamp(stampid)

参数:

stampid-整数,必须为先前的stamp()调用的返回值。

下面是上述方法的实现和一些示例:

范例1:

Python3

# 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)

输出:

6bc8d6495c50a5a31f74e7f9ae0e67b8.gif

范例2:

Python3

# 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])

输出:

c8583d7d32efe6836a377ae28e0f5f3b.gif

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值