Python turtle.shape()用法及代码示例

本文介绍了Python的turtle模块如何使用shape()函数改变turtle图形的形状,包括默认形状和预设的五种多边形形状,以及示例展示了如何应用这些形状。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python turtle.shape()海龟形状用法

turtle 模块以面向对象和面向过程的方式提供 turtle 图形基元。
由于它使用tkinter作为基础图形,因此需要安装有Tk支持的Python版本。
Python3默认带有turtle和tkinter 库,可以直接使用不需要另外安装

turtle .shape()

在turtle中默认的鼠标形状 可以使用shape()方法来更改他的形状,它总共有以下五种形状:
此函数用于将 turtle 形状设置为具有给定名称的形状,或者,如果未提供名称,则返回当前形状的名称。

用法:

turtle.shape(name=None)
带有名称的形状必须存在于Turtle Screen的形状字典中。最初有以下多边形形状:“arrow”,“turtle”,“circle”,“square”,“triangle”,“classic”。这些图像如下所示。
默认值:‘classic’
默认形状:classic
‘arrow’:
arrow
‘turtle’:
turtle
‘circle’:
circle
‘square’:
square
‘triangle’:

triangle

案例

# import package 
import turtle  
  
  
# for default shape 
turtle.forward(100) 
  
# for circle shape 
turtle.shape("circle") 
turtle.right(60) 
turtle.forward(100) 
  
# for triangle shape 
turtle.shape("triangle") 
turtle.right(60) 
turtle.forward(100) 
  
# for square shape 
turtle.shape("square") 
turtle.right(60) 
turtle.forward(100) 
  
# for arrow shape 
turtle.shape("arrow") 
turtle.right(60) 
turtle.forward(100) 
  
# for turtle shape 
turtle.shape("turtle") 
turtle.right(60) 
turtle.forward(100)

效果图

运行效果图

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宇龙神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值