import tkinter as tk
from tkinter import ttk

def create_student_card():
    # 创建主窗口
    root = tk.Tk()
    root.title("电子学生证生成器")
    root.geometry("500x300")
    root.configure(bg="#f0f0f0")

    # 证件外框（模拟卡片）
    card = tk.Frame(root, bg="white", highlightbackground="#cccccc", 
                    highlightthickness=2, bd=0)
    card.place(relx=0.5, rely=0.5, anchor="center", width=450, height=260)

    # 顶部标题栏
    header = tk.Frame(card, bg="#0056b3") # 深蓝色背景
    header.pack(fill="x")
    tk.Label(header, text="XX 省 XX 市 实验高级中学", fg="white", bg="#0056b3", 
             font=("微软雅黑", 12, "bold"), pady=5).pack()
    tk.Label(header, text="STUDENT ID CARD", fg="white", bg="#0056b3", 
             font=("Arial", 8)).pack()

    # 内容区
    content = tk.Frame(card, bg="white")
    content.pack(fill="both", expand=True, padx=20, pady=10)

    # --- 左侧：照片区 ---
    photo_frame = tk.Frame(content, bg="#e0e0e0", width=100, height=130, 
                           highlightbackground="gray", highlightthickness=1)
    photo_frame.pack_propagate(False) # 固定大小
    photo_frame.pack(side="left", padx=10)
    
    tk.Label(photo_frame, text="一寸照片\n(100x130)", bg="#e0e0e0", 
             fg="gray", font=("微软雅黑", 9)).place(relx=0.5, rely=0.5, anchor="center")

    # --- 右侧：信息区 ---
    info_frame = tk.Frame(content, bg="white")
    info_frame.pack(side="left", fill="both", expand=True, padx=20)

    details = [
        ("姓    名：", "张三 (Zhang San)"),
        ("学    号：", "2023090144"),
        ("院    系：", "计算机科学与技术学院"),
        ("出生日期：", "2007年10月24日"),
        ("有效期至：", "2027年06月30日")
    ]

    for label, value in details:
        row = tk.Frame(info_frame, bg="white")
        row.pack(fill="x", pady=2)
        tk.Label(row, text=label, bg="white", font=("微软雅黑", 10, "bold"), fg="#333").pack(side="left")
        tk.Label(row, text=value, bg="white", font=("微软雅黑", 10), fg="#555").pack(side="left")

    # --- 底部装饰：防伪码和印章 ---
    footer = tk.Frame(card, bg="white")
    footer.pack(fill="x", side="bottom", padx=20, pady=5)
    
    # 模拟条形码
    barcode = tk.Frame(footer, bg="black", width=120, height=20)
    barcode.pack(side="left")
    tk.Label(footer, text="|||| ||| || ||||| |||", bg="white", font=("Arial", 8)).place(x=0, y=0)

    # 模拟红色印章 (Canvas 绘制)
    canvas = tk.Canvas(card, width=80, height=80, bg="white", highlightthickness=0)
    canvas.place(x=340, y=150)
    canvas.create_oval(5, 5, 75, 75, outline="#ff4d4d", width=2)
    canvas.create_text(40, 30, text="学生证", fill="#ff4d4d", font=("微软雅黑", 8, "bold"))
    canvas.create_text(40, 50, text="专用章", fill="#ff4d4d", font=("微软雅黑", 8, "bold"))
    # 让印章看起来有点透明感或倾斜（由于tk限制，这里简单实现）

    root.mainloop()

if __name__ == "__main__":
    create_student_card()