GUI版的学生成绩管理系统,具有如下功能: 1)学生的信息输入,(学生,包括属性:学号,姓名,C成绩,C++成绩,python成绩) 2)显示输入的学生信息 3)按学生总分对学生降序排序。 4)计算每个学生的总分 用python写出该代码
时间: 2024-01-01 13:06:06 浏览: 205
学生成绩管理系统 系统功能基本要求 学生信息,学号、姓名、性别、专业、年级等
好的,以下是一个简单的GUI版学生成绩管理系统的Python代码实现:
```python
from tkinter import *
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 StudentManagementSystem:
def __init__(self, master):
self.master = master
master.title("学生成绩管理系统")
# 创建标签和文本框用于输入学生信息
Label(master, text="学号").grid(row=0, column=0)
self.id_entry = Entry(master)
self.id_entry.grid(row=0, column=1)
Label(master, text="姓名").grid(row=1, column=0)
self.name_entry = Entry(master)
self.name_entry.grid(row=1, column=1)
Label(master, text="C成绩").grid(row=2, column=0)
self.c_score_entry = Entry(master)
self.c_score_entry.grid(row=2, column=1)
Label(master, text="C++成绩").grid(row=3, column=0)
self.cpp_score_entry = Entry(master)
self.cpp_score_entry.grid(row=3, column=1)
Label(master, text="Python成绩").grid(row=4, column=0)
self.python_score_entry = Entry(master)
self.python_score_entry.grid(row=4, column=1)
# 创建按钮用于添加学生信息
self.add_button = Button(master, text="添加学生信息", command=self.add_student)
self.add_button.grid(row=5, column=0, columnspan=2)
# 创建标签用于显示学生信息
self.student_info_label = Label(master, text="")
self.student_info_label.grid(row=6, column=0, columnspan=2)
# 创建按钮用于按总分排序
self.sort_button = Button(master, text="按总分排序", command=self.sort_students)
self.sort_button.grid(row=7, column=0, columnspan=2)
# 创建标签用于显示学生总分
self.total_score_label = Label(master, text="")
self.total_score_label.grid(row=8, column=0, columnspan=2)
# 存储学生信息的列表
self.students = []
# 添加学生信息
def add_student(self):
try:
id = int(self.id_entry.get())
name = self.name_entry.get()
c_score = float(self.c_score_entry.get())
cpp_score = float(self.cpp_score_entry.get())
python_score = float(self.python_score_entry.get())
student = Student(id, name, c_score, cpp_score, python_score)
self.students.append(student)
self.id_entry.delete(0, END)
self.name_entry.delete(0, END)
self.c_score_entry.delete(0, END)
self.cpp_score_entry.delete(0, END)
self.python_score_entry.delete(0, END)
messagebox.showinfo("成功", "学生信息添加成功!")
except ValueError:
messagebox.showerror("错误", "输入的学生信息格式不正确!")
# 按总分排序
def sort_students(self):
self.students.sort(key=lambda x: x.total_score, reverse=True)
text = ""
for student in self.students:
text += f"学号:{student.id},姓名:{student.name},总分:{student.total_score:.2f}\n"
self.student_info_label.config(text=text)
# 计算并显示每个学生的总分
total_score_text = ""
for student in self.students:
total_score_text += f"{student.name}的总分为:{student.total_score:.2f}\n"
self.total_score_label.config(text=total_score_text)
root = Tk()
my_gui = StudentManagementSystem(root)
root.mainloop()
```
这段代码使用了Python的tkinter模块创建了一个GUI窗口,包括了输入学生信息、显示学生信息、按总分排序和计算每个学生的总分等功能。同时,使用了Python的面向对象编程思想,定义了一个Student类和一个StudentManagementSystem类,方便管理和操作学生信息。
阅读全文