Python turtle.addshape 示例说明
最编程
2024-03-17 18:50:38
...
turtle 模块以面向对象和面向过程的方式提供 turtle 图形基元。由于它使用Tkinter作为基础图形,因此需要安装有Tk支持的Python版本。
turtle .addshape()
此函数用于将海龟形状添加到TurtleScreen的形状列表中。
用法:
turtle.addshape(name, shape=None)
参数:
参数 | 描述 |
name | gif-file的名称 |
shape | 形状是一对坐标的元组 |
下面是上述方法的实现和一些示例:
范例1:
Python3
# import package
import turtle
# print list of the all
# shapes available
print(turtle.getshapes())
# add shape to the shape list
turtle.addshape(name="gfg.gif",shape=None)
# check the updated shape list
print(turtle.getshapes())
输出:
[‘arrow’, ‘blank’, ‘circle’, ‘classic’, ‘square’, ‘triangle’, ‘turtle’]
[‘arrow’, ‘blank’, ‘circle’, ‘classic’, ‘gfg.gif’, ‘square’, ‘triangle’, ‘turtle’]
范例2:
Python3
# import package
import turtle
# add shape to the shape list as above
turtle.addshape(name="gfg.gif",shape=None)
# set turtle with new shape
# and new position
turtle.shape("gfg.gif")
turtle.up()
turtle.setpos(-10,10)
turtle.down()
# loop for motion
for i in range(22):
turtle.fd(40+5*i)
turtle.right(90)
输出:
推荐阅读
-
Python scipy.signal.iirnotch 示例说明
-
NeRF 模型评估指标 PSNR、MS-SSIM、LPIPS 详细说明和 Python 实现
-
Python Wand 水印示例
-
Python+Kepler.gl 轻松制作炫酷路径动画的实现示例
-
Java 进程 getErrorStream 示例说明
-
Python 示例 6
-
如何使用 Python 从 Google Drive 下载文件(附代码示例)
-
Python scipy.signal.correlate2d 示例解释 - 参数:
-
Python difflib.get_close_matches 示例说明
-
人民日报注释语料库 (PFR) 1.标记说明 2.格式说明 3.示例 4.生语料库和熟语料库 5.其他语料库摘要