当前位置:首页 >> 脚本专栏

python turtle库画一个方格和圆实例

使用python的turtle库画一个方格和圆

打开python编译器,导入turtle库

from turtle import *

python turtle库画一个方格和圆实例

首先画一个距离为100的横线

forward(100)

python turtle库画一个方格和圆实例

顺时针旋转90度,前进100

python turtle库画一个方格和圆实例

在通过两次的旋转和平移得到方格,使用for循环重复两次

python turtle库画一个方格和圆实例

抬起笔,直接到方格的中间,也就是(50,0)坐标

penup()

goto(50,0)


python turtle库画一个方格和圆实例

开始画半径为50的圆,放下笔

pendown()

circle(50)


python turtle库画一个方格和圆实例

在圆的中心画个圆心点

goto(50,50)

dot()

python turtle库画一个方格和圆实例

最后隐藏画笔,完成绘画

python turtle库画一个方格和圆实例

总结:

以上就是关于python怎么使用turtle库画一个方格和圆的具体步骤内容,感谢大家的学习和对的支持。