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’

‘arrow’:

‘turtle’:

‘circle’:

‘square’:

‘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)
效果图

总结
到此这篇关于Python turtle.shape()用法的文章就介绍到这了,更多相关Python turtle.shape()用法内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Python HTML解析器BeautifulSoup用法实例详解【爬虫解析器】
这篇文章主要介绍了Python HTML解析器BeautifulSoup用法,结合实例形式详细分析了第三方库BeautifulSoup实现的爬虫解析器功能具体操作技巧,需要的朋友可以参考下2019-04-04
基于Python 的进程管理工具supervisor使用指南
Supervisor 是基于 Python 的进程管理工具,可以轻松管理一些需要以守护进程方式执行的程序,也就是后台任务,例如用来启动和管理基于 Tornado 写的 Web 程序。2016-09-09


最新评论