pythong模块turtle简单用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pythong模块turtle简单用法相关的知识,希望对你有一定的参考价值。

##初始化turtle:
t = turtle.Turtle() 或者 t = turtle.Pen()
##查询turtle状态
#位置
t.position()

#箭头朝向,箭头朝向按照顺时针或者逆时针偏离的角度描述,具体是顺时针或者逆时针取决于turtle.mode()的值,默认turtle.mode() = standard,表示逆时针方向;logo表示顺时针

t.heading()
#初始状态下箭头向右转20度,t.heading() = 340
t.right(20)
t.left(20)
#向前或向后
t.forward(10)
t.backward(10)
#设置turtle位置
t.goto(x,y) = t.setpos(x,y) = t.setposition(x,y)

t.setx(x)
t.sety(y)
#设置turtle方向,具体方向和turtle.mode相关,默认standard,设置为90度时,箭头指向正北
t.setheading(90)

#turtle回到初始位置和初始方向
t.home()
#画圆,第一个参数为半径,半径为正值,默认逆时针画圆,半径为负值,顺时针画圆。
#t.circle(-20,90),顺时针,半径20画弧,弧度90
#t.circle(20,90,10),第三个参数指定总共花几步画完,相当于多边形
t.circle(20)

以上是关于pythong模块turtle简单用法的主要内容,如果未能解决你的问题,请参考以下文章

Python#常用的模块和简单用法

python argpare 模块的简单用法

mysqldb模块的简单用法

python中logging模块的一些简单用法

requests模块简单用法

用Python的turtle模块画生日蛋糕