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

class GradesApp:
    def __init__(self, root):
        self.root = root
        self.root.title("成绩走向图")

        self.grades = []

        self.label = tk.Label(root, text="请输入成绩（以空格分隔）:", font=("Arial", 12))
        self.label.pack(pady=10)

        self.entry = tk.Entry(root, width=30, font=("Arial", 12))
        self.entry.pack(pady=10)

        self.plot_button = tk.Button(root, text="绘制成绩走向图", command=self.plot_grades, font=("Arial", 12))
        self.plot_button.pack(pady=20)

    def plot_grades(self):
        try:
            # 获取输入并将其转换为列表
            grades_input = self.entry.get()
            self.grades = list(map(float, grades_input.split()))

            # 绘制成绩走向图
            plt.figure(figsize=(10, 5))
            plt.plot(self.grades, marker='o')
            plt.title("成绩走向图")
            plt.xlabel("考试序号")
            plt.ylabel("成绩")
            plt.xticks(range(len(self.grades)))
            plt.grid()
            plt.ylim(0, 100)
            plt.axhline(y=60, color='r', linestyle='--', label='及格线')
            plt.legend()
            plt.show()
        except ValueError:
            messagebox.showerror("错误", "请确保输入的成绩为数字，以空格分隔。")

if __name__ == "__main__":
    root = tk.Tk()
    app = GradesApp(root)
    root.mainloop()