Create Analog Clock using Turtle in Python with Programming Ka Keeda

Create Analog Clock using Turtle in Python with Programming Ka Keeda

⏲Create Analog Clock using Turtle in Python⏲

from turtle import*
from datetime import datetime
title("Programming Ka Keeda")

def jump(dist, meet=0):
    penup()
    right(meet)
    forward(dist)
    left(meet)
    pendown()

def hand(l, s):
    forward(l*1.15)    
    right(90)
    forward(s/2.0)
    left(120)
    forward(s)
    left(120)
    forward(s)
    left(120)
    forward(s/2.0)

def make_hand_shape(name, l,s):
    reset()    
    jump(-l*0.15)
    begin_poly()
    hand(l, s)
    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:
            forward(25)
            jump(-radius-25)
        else:
            dot(3)    
            jump(-radius)
        right(6)    

def setup():
    global second__hand, minute__hand, hour__hand, writer
    mode("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)

    hideturtle()    
    writer = Turtle()
    #write mode("logo")
    writer.hideturtle()
    writer.penup()
    writer.backward(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.year
    m=monat[z.month - 1]
    t=z.day
    return "%s %d %d" %(m,t,j)

def tick():
    t=datetime.today()    
    sekunde = t.second + t.microsecond*0.000001
    minute = t.minute + sekunde/60.0
    stunde = t.hour + minute/60.0
    try:
        tracer(False)
        writer.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)
        tracer(True)
        second__hand.setheading(6*sekunde)
        minute__hand.setheading(6*minute)
        hour__hand.setheading(30*stunde)
        tracer(True)
        ontimer(tick,100)
    except Terminator:
        pass

def main():
    tracer(False)        
    setup()
    tracer(True)
    tick()
    return "EVENTLOOP"

if __name__ == "__main__":
    mode("logo")    
    msg = main()
    print(msg)

done()
Output:-
Create Analog Clock using Turtle in Python with Programming Ka Keeda

Humari "Programming Ka Keeda" website dekhne k liye dhanyawad😊.

एक टिप्पणी भेजें

0 टिप्पणियाँ
* Please Don't Spam Here. All the Comments are Reviewed by Admin.