官方装13最为致命
- 牛!Python自带画图demo
- 引言
- DEMO有什么?
- 总结
牛!Python自带画图demo
引言
我的电脑不是换新了嘛
所以
不得不重新下载Python
这一下
不得了
我下载了Python3.11.7这个版本
然后按照惯例
打开IDEL
平平无奇
但 我一不小心点到了
Help
(偶然 必然? 天意?)
DEMO有什么?
看到没有
Turtle Demo
这不是我一开始的海龟python 教学嘛
拒绝废话,直接开画!Python零基础教程之画图
兴奋呀
我就打开
不得了
不得了
我的13
原来官方已经帮我装完了
大家看看
有现在的北京时间时钟
#!/usr/bin/env python3
# -*- coding: cp1252 -*-
""" turtle-example-suite:tdemo_clock.pyEnhanced clock-program, showing date
and time------------------------------------Press STOP to exit the program!------------------------------------
"""
from turtle import *
from datetime import datetimedef jump(distanz, winkel=0):penup()right(winkel)forward(distanz)left(winkel)pendown()def hand(laenge, spitze):fd(laenge*1.15)rt(90)fd(spitze/2.0)lt(120)fd(spitze)lt(120)fd(spitze)lt(120)fd(spitze/2.0)def make_hand_shape(name, laenge, spitze):reset()jump(-laenge*0.15)begin_poly()hand(laenge, spitze)end_poly()hand_form = get_poly()register_shape(name, hand_form)def clockface(radius):reset()pensize(7)for i in range(60):jump(radius)if i % 5 == 0:fd(25)jump(-radius-25)else:dot(3)jump(-radius)rt(6)def setup():global second_hand, minute_hand, hour_hand, writermode("logo")make_hand_shape("second_hand", 125, 25)make_hand_shape("minute_hand", 130, 25)make_hand_shape("hour_hand", 90, 25)clockface(160)second_hand = Turtle()second_hand.shape("second_hand")second_hand.color("gray20", "gray80")minute_hand = Turtle()minute_hand.shape("minute_hand")minute_hand.color("blue1", "red1")hour_hand = Turtle()hour_hand.shape("hour_hand")hour_hand.color("blue3", "red3")for hand in second_hand, minute_hand, hour_hand:hand.resizemode("user")hand.shapesize(1, 1, 3)hand.speed(0)ht()writer = Turtle()#writer.mode("logo")writer.ht()writer.pu()writer.bk(85)def wochentag(t):wochentag = ["Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday", "Sunday"]return wochentag[t.weekday()]def datum(z):monat = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "June","July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."]j = z.yearm = monat[z.month - 1]t = z.dayreturn "%s %d %d" % (m, t, j)def tick():t = datetime.today()sekunde = t.second + t.microsecond*0.000001minute = t.minute + sekunde/60.0stunde = t.hour + minute/60.0try:tracer(False) # Terminator can occur herewriter.clear()writer.home()writer.forward(65)writer.write(wochentag(t),align="center", font=("Courier", 14, "bold"))writer.back(150)writer.write(datum(t),align="center", font=("Courier", 14, "bold"))writer.forward(85)second_hand.setheading(6*sekunde) # or hereminute_hand.setheading(6*minute)hour_hand.setheading(30*stunde)tracer(True)ontimer(tick, 100)except Terminator:pass # turtledemo user pressed STOPdef main():tracer(False)setup()tracer(True)tick()return "EVENTLOOP"if __name__ == "__main__":mode("logo")msg = main()print(msg)mainloop()
有跳舞的三角形
妙哉妙哉
有19个demo
这么多demo
够我们好好学习辣
且
允许我们添加自己的demo
也就是说,可以变成一个私人的画图库
总结
大家快去玩一玩
感觉这个demo可以玩的事情挺多
可以发挥下想象力
比如 桌面时钟?
让我想想如何实现
等我想出来
(这字不是我写的)