python turtle教程1

2025-11-20 20:30:30

1、首先我们import turtle,如果没报错就说明成功引用了turtle了。如果报错请在cmd命令行中输入pip install turtle。

python turtle教程1

2、 turtle.position()用来获取当前箭头的位置,一开始调用这个函数会初始化一个tk,位置为(0,0)

turtle.forward(x) 或者 turtle.fd(x) 沿着箭头方向前进x距离。

python turtle教程1

3、turtle.backward(x) 或者 turtle.bk(x) 沿着箭头反方向前进x距离。

python turtle教程1

4、turtle.heading()获取当前箭头的角度,一开始为0度。

turtle.right(x)或者 turtle.rt(x) 箭头方向向右旋转x度。

python turtle教程1

5、turtle.left(x)或者 turtle.lt(x) 箭头方向向左旋转x度。

python turtle教程1

6、turtle.setpos(x,y) 或者 turtle.goto(x,y) 或者 turtle.setposition(x,y)

直接去到某一个坐标(x,y)

python turtle教程1

7、turtle.setx(x)设置x坐标

turtle.sety(y)设置y坐标

python turtle教程1

python turtle教程1

8、turtle.setheading(x) 或者 turtle.seth(x) 设置角度x

python turtle教程1

9、turtle.home()返回原点,并且箭头方向为0度。

python turtle教程1

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢