import turtle as t
from datetime import*
def Skip(step):
    t.penup()
    t.forward(step)
    t.pendown()
def mkHand(name,length):
    t.reset()
    Skip(-length*0.1)
    t.begin_poly()
    t.forward(length*1.1)
    t.end_poly()
    handFrom=t.get_poly()
    t.register_shape(name,handFrom)
def Init():
    global secHand,minHand,hurHand,printer
    t.mode('logo')
    mkHand('secHand',135)
    mkHand('minHand',125)
    mkHand('hurHand',90)
    secHand=t.Turtle()
    secHand.pencolor('green')
    secHand.shape('secHand')
    minHand=t.Turtle()
    minHand.pencolor('red')
    minHand.shape('minHand')
    hurHand=t.Turtle()
    hurHand.pencolor('blue')
    hurHand.shape('hurHand')
    for hand in secHand,minHand,hurHand:
        hand.shapesize(1,1,3)
        hand.speed(0)
    printer=t.Turtle()
    printer.hideturtle()
    printer.penup()
def SetupClock(radius):
    t.reset()
    t.pensize(7)
    for i in range(60):
        Skip(radius)
        if i%5 == 0:
            t.pencolor('red')
            t.forward(20)
            Skip(-radius-20)
            Skip(radius+20)
            if i == 0:
                t.write(int(12),align='center',font=('华文行楷',14,'bold'))
            elif i == 30:
                Skip(25)
                t.write(int(i/5),align='center',font=('华文行楷',14,'bold'))
                Skip(-25)
            elif (i == 25 or i == 35):
                Skip(20)
                t.write(int(i/5),align='center',font=('华文行楷',14,'bold'))
                Skip(-20)
            else:
                t.write(int(i/5),align='center',font=('华文行楷',14,'bold'))
                Skip(-radius-20)
        else:
            t.dot(5,'blue')
            Skip(-radius)
        t.right(6)
def Week(n):
    week=['周一','周二','周三','周四','周五','周六','周日']
    return week[n.weekday()]
def Date(n):
    y=n.year
    m=n.month
    d=n.day
    return '%s%d%d日'%(y,m,d)
def Tick():
    n=datetime.today()
    second=n.second+n.microsecond*0.000001
    minute=n.minute+second/60.0
    hour=n.hour+minute/60.0
    secHand.setheading(6*second)
    minHand.setheading(6*minute)
    hurHand.setheading(30*hour)
    t.tracer(False)
    printer.pencolor('blue')
    printer.forward(65)
    printer.write(Week(n),align='center',font=('华文行楷',14,'bold'))
    printer.back(130)
    printer.write(Date(n),align='center',font=('华文行楷',14,'bold'))
    printer.home()
    t.tracer(True)
    t.ontimer(Tick,100)
def main():
    t.tracer(False)
    Init()
    SetupClock(160)
    t.tracer(True)
    Tick()
    t.mainloop()
main()