日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python动态电子时钟包装_Python小项目:开发一个动态时钟小程序(附源码)

發布時間:2024/5/8 66 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python动态电子时钟包装_Python小项目:开发一个动态时钟小程序(附源码) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

importturtlefrom datetime import *

#抬起畫筆,向前運動一段距離放下

defskip(step):

turtle.penup()

turtle.forward(step)

turtle.pendown()defmkHand(name, length):#注冊Turtle形狀,建立表針Turtle

turtle.reset()#先反向運動一段距離,終點作為繪制指針的起點

skip(-length * 0.1)#開始記錄多邊形的頂點。當前的烏龜位置是多邊形的第一個頂點。

turtle.begin_poly()

turtle.forward(length* 1.1)#停止記錄多邊形的頂點。當前的烏龜位置是多邊形的最后一個頂點。將與第一個頂點相連。

turtle.end_poly()#返回最后記錄的多邊形。

handForm =turtle.get_poly()

turtle.register_shape(name, handForm)definit():globalsecHand, minHand, houHand, printer#重置Turtle指向北

turtle.mode("logo")#建立三個表針Turtle并初始化

mkHand("secHand", 135)

mkHand("minHand", 125)

mkHand("houHand", 90)

secHand=turtle.Turtle()

secHand.shape("secHand")

minHand=turtle.Turtle()

minHand.shape("minHand")

houHand=turtle.Turtle()

houHand.shape("houHand")for hand insecHand, minHand, houHand:

hand.shapesize(1, 1, 3)

hand.speed(0)#建立輸出文字Turtle

printer =turtle.Turtle()#隱藏畫筆的turtle形狀

printer.hideturtle()

printer.penup()#繪制表盤

defsetupClock(radius):#建立表的外框

turtle.reset()

turtle.pensize(7)for i in range(60):#向前移動半徑值

skip(radius)if i % 5 ==0:#畫長刻度線

turtle.forward(20)#回到中心點

skip(-radius - 20)#移動到刻度線終點

skip(radius + 20)#下面是寫表盤刻度值,為了不與劃線重疊,所以對于特殊位置做了處理

if i ==0:

turtle.write(int(12), align="center", font=("Courier", 14, "bold"))elif i == 30:

skip(25)

turtle.write(int(i/ 5), align="center", font=("Courier", 14, "bold"))

skip(-25)elif (i == 25 or i == 35):

skip(20)

turtle.write(int(i/ 5), align="center", font=("Courier", 14, "bold"))

skip(-20)else:

turtle.write(int(i/ 5), align="center", font=("Courier", 14, "bold"))#回到中心點

skip(-radius - 20)else:#畫圓點

turtle.dot(5)

skip(-radius)#順時針移動6°

turtle.right(6)defweek(t):

week= ["星期一", "星期二", "星期三","星期四", "星期五", "星期六", "星期日"]returnweek[t.weekday()]defdate(t):

y=t.year

m=t.month

d=t.dayreturn "%s %d%d" %(y, m, d)deftick():#繪制表針的動態顯示

t =datetime.today()

second= t.second + t.microsecond * 0.000001minute= t.minute + second / 60.0hour= t.hour + minute / 60.0secHand.setheading(6 *second)

minHand.setheading(6 *minute)

houHand.setheading(30 *hour)

turtle.tracer(False)

printer.forward(65)

printer.write(week(t), align="center",

font=("Courier", 14, "bold"))

printer.back(130)

printer.write(date(t), align="center",

font=("Courier", 14, "bold"))

printer.home()

turtle.tracer(True)#100ms后繼續調用tick

turtle.ontimer(tick, 100)defmain():#打開/關閉龜動畫,并為更新圖紙設置延遲。

turtle.tracer(False)

init()

setupClock(160)

turtle.tracer(True)

tick()

turtle.mainloop()if __name__ == "__main__":

main()

總結

以上是生活随笔為你收集整理的python动态电子时钟包装_Python小项目:开发一个动态时钟小程序(附源码)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。