您好,登錄后才能下訂單哦!
這篇文章主要介紹python怎么實現簡易動態(tài)時鐘,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
具體內容如下
from turtle import * from datetime import * #移動到指定位置 def skip(step): penup() forward(step) pendown() #畫指針 def drawpointer(name, length): reset() skip(-length*0.1) begin_poly() forward(length*1.1) end_poly() handForm = get_poly() register_shape(name, handForm) #初始化 def init(): global hrpointer, minpointer, secpointer, weektext #設置turtle Logo模式,朝北 mode("logo") drawpointer("hrpointer", 90) drawpointer("minpointer", 130) drawpointer("secpointer", 140) hrpointer = Turtle() hrpointer.shape("hrpointer") minpointer = Turtle() minpointer.shape("minpointer") secpointer = Turtle() secpointer.shape("secpointer") secpointer.pencolor("red") for pointer in hrpointer, minpointer, secpointer: pointer.shapesize(3, 1, 1) pointer.speed(0) #文字輸出 weektext = Turtle() weektext.hideturtle() weektext.penup() #設置表盤形狀 def setupClock(radius): reset() # clockPanel = Turtle() pensize(7) pencolor("blue") for i in range(60): skip(radius) if i%5 == 0: forward(20) skip(-radius-20) else: dot(5) skip(-radius) right(6) #星期文本 def Week(t): week = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] return week[t.weekday()] #日期文本 def Date(t): y = t.year m = t.month d = t.day return "%s %d %d" % (y, m, d) #繪制表針動態(tài)顯示 def tick(): t = datetime.today() second = t.second + t.microsecond*0.0000001 minute = t.minute + second/60.0 hour = t.hour + minute/60.0 secpointer.setheading(6*second) minpointer.setheading(6*minute) hrpointer.setheading(30*hour) tracer(False) weektext.forward(65) weektext.write(Week(t), align="center",font=("Courier", 14, "bold")) weektext.back(130) weektext.write(Date(t), align="center",font=("Courier", 14, "bold")) weektext.home() tracer(True) #間隔100ms調用一次 ontimer(tick, 100) def main(): tracer(False) init() setupClock(160) tracer(True) tick() mainloop() if __name__ == '__main__': main()
以上是“python怎么實現簡易動態(tài)時鐘”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業(yè)資訊頻道!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。