mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4mobile wallpaper 5mobile wallpaper 6
首页 / 学习 / python-Day1
55 字
1 分钟
python-Day1
2025-04-08
无标签

简单的python画图代码学习#

main.py

# coding: utf-8
from turtle import *
from customer import action
def clean_screen():
clear()
penup()
home()
pendown()
showturtle()
def close():
bye()
def main():
setup(width=800, height=600, startx=0, starty=0)
title('按 S 开始绘图,按 D 清除界面,按 Esc 关闭')
showturtle()
speed(2)
onkeyrelease(action, 's')
onkeyrelease(clean_screen, 'd')
onkeyrelease(close, 'Escape')
listen()
done()
if __name__ == '__main__':
main()

简单的学习逻辑画图

比如:画三角形

customer.py

# coding: utf-8
from turtle import *
def action():
forward(10)
right(120)
forward(10)
right(120)
forward(10)
right(120)

第二个正方形:

# coding: utf-8
from turtle import *
def action():
forward(99)
right(90)
forward(99)
right(90)
forward(99)
right(90)
forward(99)

其实是动画的形式的

先学这么多,下次见ξ( ✿>◡❛)

分享

如果这篇文章对你有帮助,欢迎分享给更多人!

python-Day1
https://npiter.de/posts/python-day1/
作者
piter
发布于
2025-04-08
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

封面
Sample Song
Sample Artist
封面
Sample Song
Sample Artist
0:00 / 0:00