GUI版的学生成绩管理系统,具有如下功能: 1)学生的信息输入,(学生,包括属性:学号,姓名,C成绩,C++成绩,python成绩) 2)显示输入的学生信息 3)按学生总分对学生降序排序。 4)计算每个学生的总分
时间: 2024-01-02 14:02:48 浏览: 74
学生成绩管理系统 系统功能基本要求 学生信息,学号、姓名、性别、专业、年级等
好的,根据您的需求,我给您提供一个简单的GUI版的学生成绩管理系统,具有如下功能:
1. 学生的信息输入,包括学号、姓名、C成绩、C++成绩、Python成绩。
2. 显示输入的学生信息。
3. 按学生总分对学生降序排序。
4. 计算每个学生的总分。
```
import tkinter as tk
from tkinter import messagebox
class Student:
def __init__(self, id, name, c_score, cpp_score, python_score):
self.id = id
self.name = name
self.c_score = c_score
self.cpp_score = cpp_score
self.python_score = python_score
self.total_score = c_score + cpp_score + python_score
class GradeManager:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def get_students(self):
return self.students
def sort_students_by_total_score_desc(self):
self.students.sort(key=lambda student: student.total_score, reverse=True)
class GUI:
def __init__(self, parent):
self.parent = parent
self.grade_manager = GradeManager()
self.create_widgets()
def create_widgets(self):
# Label for id
tk.Label(self.parent, text="ID").grid(row=0, column=0)
self.id_entry = tk.Entry(self.parent)
self.id_entry.grid(row=0, column=1)
# Label for name
tk.Label(self.parent, text="Name").grid(row=1, column=0)
self.name_entry = tk.Entry(self.parent)
self.name_entry.grid(row=1, column=1)
# Label for c_score
tk.Label(self.parent, text="C Score").grid(row=2, column=0)
self.c_score_entry = tk.Entry(self.parent)
self.c_score_entry.grid(row=2, column=1)
# Label for cpp_score
tk.Label(self.parent, text="C++ Score").grid(row=3, column=0)
self.cpp_score_entry = tk.Entry(self.parent)
self.cpp_score_entry.grid(row=3, column=1)
# Label for python_score
tk.Label(self.parent, text="Python Score").grid(row=4, column=0)
self.python_score_entry = tk.Entry(self.parent)
self.python_score_entry.grid(row=4, column=1)
# Button for adding a student
tk.Button(self.parent, text="Add student", command=self.add_student).grid(row=5, columnspan=2)
# Button for sorting students
tk.Button(self.parent, text="Sort students by total score", command=self.sort_students).grid(row=6, columnspan=2)
# Listbox for displaying students
self.listbox = tk.Listbox(self.parent)
self.listbox.grid(row=7, columnspan=2)
def add_student(self):
id = self.id_entry.get()
name = self.name_entry.get()
c_score = int(self.c_score_entry.get())
cpp_score = int(self.cpp_score_entry.get())
python_score = int(self.python_score_entry.get())
student = Student(id, name, c_score, cpp_score, python_score)
self.grade_manager.add_student(student)
self.list_students()
def sort_students(self):
self.grade_manager.sort_students_by_total_score_desc()
self.list_students()
def list_students(self):
self.listbox.delete(0, tk.END)
for student in self.grade_manager.get_students():
self.listbox.insert(tk.END, "ID: {}, Name: {}, C Score: {}, C++ Score: {}, Python Score: {}, Total Score: {}".format(student.id, student.name, student.c_score, student.cpp_score, student.python_score, student.total_score))
if __name__ == "__main__":
root = tk.Tk()
root.title("Grade Manager")
gui = GUI(root)
root.mainloop()
```
这个程序中,我们定义了一个学生类`Student`,包含学生的学号、姓名、C成绩、C++成绩、Python成绩和总分。然后定义了一个成绩管理类`GradeManager`,包含添加学生、获取学生列表和按总分排序的方法。最后,我们使用Tkinter来创建GUI界面,包含添加学生的表单、排序按钮和显示学生列表的列表框。在添加学生时,我们创建一个`Student`对象并添加到`GradeManager`中,然后重新显示学生列表。在按总分排序时,我们调用`GradeManager`的排序方法,然后重新显示学生列表。
阅读全文