python turtle教程1

2024-10-28 22:33:34

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

python turtle教程1

2、turtle.position()用来获取当前箭头的位置,一开始调用这个函数会初始化一个tk,位置为(0,0)turtle.forwar颊俄岿髭d(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教程1python turtle教程1

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

python turtle教程1

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

python turtle教程1
猜你喜欢