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()用法内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
tensorflow1.0学习之模型的保存与恢复(Saver)
这篇文章主要介绍了tensorflow1.0学习之模型的保存与恢复(Saver) ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-04-04
pytorch中关于distributedsampler函数的使用
这篇文章主要介绍了pytorch中关于distributedsampler函数的使用,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-02-02


最新评论