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标准模块--ContextManager上下文管理器的具体用法
本篇文章主要介绍了Python标准模块--ContextManager的具体用法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-11-11Python使用matplotlib绘图无法显示中文问题的解决方法
这篇文章主要介绍了Python使用matplotlib绘图无法显示中文问题的解决方法,结合具体实例形式分析了Python使用matplotlib绘图时出现中文乱码的原因与相关解决方法,需要的朋友可以参考下2018-03-03老生常谈Python startswith()函数与endswith函数
下面小编就为大家带来一篇老生常谈Python startswith()函数与endswith函数。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-09-09
最新评论