while True:now = datetime.now()print(now.strftime("%H:%M:%S"))time.sleep(1)
while True:now = datetime.now()print(now.strftime("%H:%M:%S %A"))time.sleep(1)
import turtle创建画布screen = turtle.Screen()创建时钟表面clock = turtle.Turtle()clock.shape("circle")clock.shapesize(10, 10)创建时针hour = turtle.Turtle()hour.shape("triangle")hour.shapesize(1, 10)创建分针minute = turtle.Turtle()minute.shape("triangle")minute.shapesize(1, 15)创建秒针second = turtle.Turtle()second.shape("triangle")second.shapesize(1, 20)将时钟表面移动到中心clock.penup()clock.goto(0, 0)clock.pendown()将时针、分针和秒针移动到初始位置hour.penup()hour.goto(0, -50)hour.pendown()minute.penup()minute.goto(0, -75)minute.pendown()second.penup()second.goto(0, -100)second.pendown()设置速度hour.speed(0)minute.speed(0)second.speed(0)主循环while True:获取当前时间now = datetime.now()更新时针、分针和秒针的位置hour.setHeading(-30 now.hour - 0.5 now.minute)minute.setheading(-6 now.minute - 0.1 now.second)second.setheading(-6 now.second)更新屏幕screen.update()
本文地址:https://www.qianwe.com/article/6c8fb75c835885cf38c5.html