from turtle import *
from datetime import *
def skip(step):
penup()
forward(step)
pendown()
def mkhand(name, length):
#註冊turtle形狀,建立表針turtle
reset()
skip(-length*0.1)
begin_poly()
forward(length*1.1)
end_poly()
handform = get_poly()
#註冊turtle形狀命令register_shape(name,shape=none)
register_shape(name, handform)
def init():
global sechand, minhand, hurhand, printer
mode("logo")# 重置turtle指向北
#建立三個表針turtle並初始化
#第二個引數為長度
mkhand("sechand", 125)
mkhand("minhand", 130)
mkhand("hurhand", 90)
sechand = turtle()
sechand.shape("sechand")
minhand = turtle()
minhand.shape("minhand")
hurhand = turtle()
hurhand.shape("hurhand")
for hand in sechand, minhand, hurhand:
hand.shapesize(1, 1, 3)
hand.speed(0)
#建立輸出文字turtle
printer = turtle()
printer.hideturtle()
printer.penup()
def setupclock(radius):
#建立表的外框
reset()
pensize(7)
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)
def tick():
#繪製表針的動態顯示
#當前時間
t = datetime.today()
second = t.second + t.microsecond*0.000001
minute = t.minute + second/60.0
hour = t.hour + minute/60.0
sechand.setheading(6*second)
minhand.setheading(6*minute)
hurhand.setheading(30*hour)
#介入tracer函式以控制重新整理速度
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()
tracer(true)
ontimer(tick, 100)#100ms後繼續呼叫tick
def main():
tracer(false)
init()
setupclock(160)
tracer(true)
tick()
mainloop()
if __name__ == "__main__":
main()
JS 電子時鐘
思路 獲取當前時間的時間物件 從時間物件中獲取當前的時間資訊,寫入到頁面中 注意 獲取的月份是從0開始的 星期,0是週日,還需要將數值轉化為漢字 d div d.innerhtml nowtime setinterval function 1000 建立當前時間物件 var d newdate 獲取...
Qt LCD電子時鐘
先上效果圖吧 就是這個樣子,簡單的時間顯示時間。這裡需要注意的是,我們最好建立乙個空檔案,這裡我們需要建立乙個整合qlcdnumber的類 具體方法如下圖 一下是源 digiclock.h ifndef digiclock h define digiclock h include include c...
tkinter實現電子時鐘
一 import tkinter import threading import datetime import time tkinter.tk overrideredirect true 不顯示標題欄 attributes alpha 0.9 半透明 attributes topmost 1 總是...