前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >程序猿的520

程序猿的520

作者头像
麒思妙想
发布2021-06-15 16:07:15
3800
发布2021-06-15 16:07:15
举报
文章被收录于专栏:麒思妙想

刚好今天520,那么作为程序员,整点活!用 turtle 表个白...

程序员的浪漫

先验货

上代码:

代码语言:javascript
复制
# 导入需要用到的模块
import turtle as tt
import time
# 画爱心的顶部
def LittleHeart():
    for i in range(200):
        tt.right(1)
        tt.forward(2)

love = '520'

# 窗口大小
tt.setup(width=800, height=500)
# 颜色
tt.color('red', 'pink')
# 笔粗细
tt.pensize(5)
# 速度
tt.speed(2)
# 提笔
tt.up()
# 隐藏笔
tt.hideturtle()
# 去到的坐标,窗口中心为0,0
tt.goto(0, -180)
tt.showturtle()
# 画上线
tt.down()
tt.speed(1)
tt.begin_fill()
tt.left(140)
tt.forward(224)
# 调用画爱心左边的顶部
LittleHeart()
# 调用画爱右边的顶部
tt.left(120)
LittleHeart()
# 画下线
tt.forward(224)
tt.end_fill()
tt.pensize(5)
tt.up()
tt.hidett()
# 在心中写字 一次
tt.goto(0, 0)
tt.showtt()
tt.color('#CD5C5C', 'pink')
# 在心中写字 font可以设置字体自己电脑有的都可以设 align开始写字的位置
tt.write(love, font=('kaiti', 40,), align="center")
tt.up()
tt.hidett()
time.sleep(2)
# 在心中写字 二次
tt.goto(0, 0)
tt.showtt()
tt.color('red', 'pink')
tt.write(love, font=('kaiti', 40,), align="center")
tt.up()
tt.hidett()
# 点击窗口关闭
window = tt.Screen()
window.exitonclick()

也许需要的前戏

如果你是windows,安装turtle可能会出现下面问题

代码语言:javascript
复制
(studyenv) E:\working\GBase\django_orm_48s\codespace\django_gbasedbt>pip install turtle
Collecting turtle
  Downloading turtle-0.0.2.tar.gz (11 kB)
    ERROR: Command errored out with exit status 1:
     command: 'E:\devlop\envs\anaconda\envs\studyenv\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\dafei\\AppData\\Local\\Temp\\pip-install-i3wdw9zc\\turtle_bb87823cd0bf40c7b00659bf322275b4\\setup.p
y'"'"'; __file__='"'"'C:\\Users\\dafei\\AppData\\Local\\Temp\\pip-install-i3wdw9zc\\turtle_bb87823cd0bf40c7b00659bf322275b4\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'
"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\dafei\AppData\Local\Temp\pip-pip-egg-info-haf9ipy6'
         cwd: C:\Users\dafei\AppData\Local\Temp\pip-install-i3wdw9zc\turtle_bb87823cd0bf40c7b00659bf322275b4\
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\dafei\AppData\Local\Temp\pip-install-i3wdw9zc\turtle_bb87823cd0bf40c7b00659bf322275b4\setup.py", line 40
        except ValueError, ve:
                         ^

    SyntaxError: invalid syntax
    ----------------------------------------

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

把turtle的安装包下载下来, setup.py 的 40行修改成 except (*ValueError*, ve): ,再安装,走起。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-05-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 麒思妙想 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 程序员的浪漫
  • 也许需要的前戏
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档