import pygame
import sys
import time  # 用来获取系统时间

# 初始化Pygame
pygame.init()

# 窗口设置
WIDTH, HEIGHT = 500, 200
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Pygame 时钟")

# 颜色
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 180, 255)

# 字体（用内置字体，绝对不报错）
font = pygame.font.Font(None, 80)
font_date = pygame.font.Font(None, 40)

# 时钟控制
clock = pygame.time.Clock()

# 主循环
running = True
while running:
    screen.fill(BLACK)  # 黑色背景

    # 退出事件
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # ========== 获取系统时间 ==========
    current_time = time.strftime("%H:%M:%S")       # 时:分:秒
    current_date = time.strftime("%Y-%m-%d")       # 年-月-日

    # ========== 渲染文字 ==========
    time_surf = font.render(current_time, True, BLUE)
    date_surf = font_date.render(current_date, True, WHITE)

    # ========== 居中显示 ==========
    screen.blit(time_surf, (WIDTH//2 - time_surf.get_width()//2, 50))
    screen.blit(date_surf, (WIDTH//2 - date_surf.get_width()//2, 130))

    # 更新画面
    pygame.display.flip()
    clock.tick(30)  # 30帧刷新

pygame.quit()
sys.exit()