import tkinter as tk
from tkinter import messagebox
import matplotlib.pyplot as plt

# =======================
# 成绩数据（可自行修改）
# =======================
exams = ["第一次月考", "期中考试", "第二次月考", "期末考试"]

scores = {
    "语文": [88, 92, 90, 95],
    "数学": [85, 89, 93, 96],
    "英语": [90, 91, 93, 94]
}

# =======================
# 绘制成绩走势图
# =======================
def draw_chart():
    plt.rcParams["font.sans-serif"] = ["SimHei"]  # 中文显示
    plt.rcParams["axes.unicode_minus"] = False

    plt.figure(figsize=(8, 5))

    for subject, values in scores.items():
        plt.plot(exams, values, marker="o", label=subject)

    plt.title("成绩走势图")
    plt.xlabel("考试")
    plt.ylabel("分数")
    plt.ylim(60, 100)
    plt.legend()
    plt.grid(True)
    plt.tight_layout()
    plt.show()

# =======================
# 统计信息
# =======================
def show_stats():
    info = ""
    for subject, values in scores.items():
        avg = sum(values) / len(values)
        info += f"{subject}：最高 {max(values)}，最低 {min(values)}，平均 {avg:.1f}\n"
    messagebox.showinfo("成绩统计", info)

# =======================
# GUI 界面
# =======================
root = tk.Tk()
root.title("成绩走势分析")
root.geometry("320x260")

tk.Label(root, text="成绩管理系统", font=("微软雅黑", 16)).pack(pady=15)

tk.Button(
    root,
    text="📈 查看成绩走势图",
    width=25,
    height=2,
    command=draw_chart
).pack(pady=10)

tk.Button(
    root,
    text="📊 查看成绩统计",
    width=25,
    height=2,
    command=show_stats
).pack(pady=10)

tk.Button(
    root,
    text="退出",
    width=25,
    command=root.quit
).pack(pady=10)

root.mainloop()