0% found this document useful (0 votes)
10 views

import turtle

This document contains a Python script that uses the Turtle graphics library to create a digital clock. The clock displays the current hour, minute, and second using lines drawn on the screen, updating every second. The background is set to black, and the clock's hands are colored white and green.

Uploaded by

Ayush Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

import turtle

This document contains a Python script that uses the Turtle graphics library to create a digital clock. The clock displays the current hour, minute, and second using lines drawn on the screen, updating every second. The background is set to black, and the clock's hands are colored white and green.

Uploaded by

Ayush Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import turtle

import time

wn = turtle.Screen()

wn.bgcolor("black")

wn.setup(600, 600)

wn.tracer(0)

pen = turtle.Turtle()

pen.hideturtle()

pen.speed(0)

pen.pensize(3)

def draw_clock(h, m, s, clock):

clock.penup()

clock.goto(0, 210)

clock.setheading(180)

clock.color("green")

clock.pendown()

clock.circle(210)

clock.penup()

clock.goto(0, 0)

clock.setheading(90)

for _ in range(12):

clock.fd(190)

clock.pendown()

clock.fd(20)

clock.penup()

clock.goto(0, 0)
clock.rt(30)

pen.penup()

pen.goto(0, 0)

pen.color("white")

pen.setheading(90)

ang = (h / 12) * 360

pen.rt(ang)

pen.pendown()

pen.fd(100)

pen.penup()

pen.goto(0, 0)

pen.color("white")

pen.setheading(90)

ang = (m / 60) * 360

pen.rt(ang)

pen.pendown()

pen.fd(150)

pen.penup()

pen.goto(0, 0)

pen.color("white")

pen.setheading(90)

ang = (s / 60) * 360

pen.rt(ang)

pen.pendown()

pen.fd(200)

while True:

h = int(time.strftime("%I"))
m = int(time.strftime("%M"))

s = int(time.strftime("%S"))

draw_clock(h, m, s, pen)

wn.update()

time.sleep(1)

pen.clear()

You might also like