import pygame

# 初始化
pygame.init()
WIDTH, HEIGHT = 500, 300
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Pygame 秒表计时器")

# 字体（支持中文）
try:
    font = pygame.font.Font("simhei.ttf", 80)
except:
    font = pygame.font.SysFont("Arial", 80)

clock = pygame.time.Clock()
start_ticks = pygame.time.get_ticks()  # 起始时间
running = True

while running:
    screen.fill((10, 15, 30))
    # 事件处理
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # 计算已过秒数
    total_ms = pygame.time.get_ticks() - start_ticks
    sec = total_ms // 1000
    ms = (total_ms % 1000) // 10  # 保留两位毫秒

    # 格式化时间 00:00
    time_text = f"{sec:02d}.{ms:02d}"
    text_surface = font.render(time_text, True, (255, 255, 0))
    # 居中绘制
    rect = text_surface.get_rect(center=(WIDTH//2, HEIGHT//2))
    screen.blit(text_surface, rect)

    pygame.display.update()
    clock.tick(60)

pygame.quit()