以下是一个简单的Python代码,用于绘制带有时间、星期、日期的数字时钟:

import time
import turtle

# 设置画布和画笔
canvas = turtle.Screen()
canvas.bgcolor('black')
canvas.title('Digital Clock')
pen = turtle.Turtle()
pen.hideturtle()
pen.speed(0)
pen.pensize(3)

# 显示时间、星期和日期
def show_time():
    # 获取当前时间、星期和日期
    current_time = time.strftime('%H:%M:%S')
    current_weekday = time.strftime('%A')
    current_date = time.strftime('%B %d, %Y')
    
    # 绘制时间、星期和日期
    pen.penup()
    pen.goto(0, 100)
    pen.clear()
    pen.write(current_time, align='center', font=('Courier', 40, 'normal'))
    pen.goto(0, 0)
    pen.write(current_weekday, align='center', font=('Courier', 20, 'normal'))
    pen.goto(0, -50)
    pen.write(current_date, align='center', font=('Courier', 20, 'normal'))
    
    # 每隔一秒钟更新一次时间
    canvas.ontimer(show_time, 1000)

# 启动时钟
show_time()
turtle.done()

运行代码后,将会出现一个黑色背景的窗口,上面显示当前时间、星期和日期。窗口将每秒钟更新一次时间。可以根据需要调整字体、颜色、大小等参数。

Python绘制带时间、星期和日期的数字时钟

原文地址: https://www.cveoy.top/t/topic/nyrp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录