import pygame
import datetime
import sys

# --- 1. 初始化 ---
pygame.init()
screen = pygame.display.set_mode((600, 300))
pygame.display.set_caption("Pygame 时间显示器")
clock = pygame.time.Clock()

# 颜色定义
BG_COLOR = (30, 30, 30)      # 深灰色背景
TIME_COLOR = (0, 255, 100)   # 荧光绿时间
DATE_COLOR = (200, 200, 200) # 浅灰色日期

# 字体设置
try:
    # 尝试加载数字感较强的字体，如果没有则使用默认
    font_big = pygame.font.SysFont("consolas", 80, bold=True)
    font_small = pygame.font.SysFont("simhei", 30)
except:
    font_big = pygame.font.SysFont("arial", 80)
    font_small = pygame.font.SysFont("arial", 30)

def run_clock():
    running = True
    while running:
        # --- 2. 事件处理 ---
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        # --- 3. 获取时间 ---
        now = datetime.datetime.now()
        # 格式化时间字符串
        time_str = now.strftime("%H:%M:%S")      # 时:分:秒
        date_str = now.strftime("%Y-%m-%d")      # 年-月-日
        weekday_str = "星期" + ["一","二","三","四","五","六","日"][now.weekday()]

        # --- 4. 绘制界面 ---
        screen.fill(BG_COLOR)

        # 渲染日期和星期
        date_surface = font_small.render(f"{date_str}  {weekday_str}", True, DATE_COLOR)
        date_rect = date_surface.get_rect(center=(300, 80))
        screen.blit(date_surface, date_rect)

        # 渲染大数字时间
        time_surface = font_big.render(time_str, True, TIME_COLOR)
        time_rect = time_surface.get_rect(center=(300, 160))
        
        # 给时间加一个简单的发光阴影效果
        shadow_surface = font_big.render(time_str, True, (0, 100, 40))
        screen.blit(shadow_surface, (time_rect.x + 4, time_rect.y + 4))
        screen.blit(time_surface, time_rect)

        # 底部提示
        hint_surface = font_small.render("实时系统时间", True, (100, 100, 100))
        screen.blit(hint_surface, (210, 240))

        # --- 5. 更新屏幕 ---
        pygame.display.flip()
        clock.tick(10)  # 每秒更新10次即可，节省CPU

    pygame.quit()
    sys.exit()

if __name__ == "__main__":
    run_clock()