用Python编写1. GUI版的学生成绩管理系统,具有如下功能: 1)学生的信息输入,(学生,包括属性:学号,姓名,C成绩,C++成绩,python成绩) 2)显示输入的学生信息 3)按学生总分对学生降序排序。 4)计算每个学生的总分
时间: 2024-01-02 16:02:17 浏览: 73
基于Python实现学生成绩管理系统【100010845】
5星 · 资源好评率100%
好的,下面是一个Python实现的GUI版学生成绩管理系统,包含以上功能:
```python
import tkinter as tk
from tkinter import messagebox
class Student:
def __init__(self, sno, name, c_score, cpp_score, python_score):
self.sno = sno
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):
self.students = []
self.window = tk.Tk()
self.window.title("学生成绩管理系统")
self.window.geometry("400x400")
sno_label = tk.Label(self.window, text="学号")
sno_label.grid(row=0, column=0)
self.sno_entry = tk.Entry(self.window)
self.sno_entry.grid(row=0, column=1)
name_label = tk.Label(self.window, text="姓名")
name_label.grid(row=1, column=0)
self.name_entry = tk.Entry(self.window)
self.name_entry.grid(row=1, column=1)
c_score_label = tk.Label(self.window, text="C成绩")
c_score_label.grid(row=2, column=0)
self.c_score_entry = tk.Entry(self.window)
self.c_score_entry.grid(row=2, column=1)
cpp_score_label = tk.Label(self.window, text="C++成绩")
cpp_score_label.grid(row=3, column=0)
self.cpp_score_entry = tk.Entry(self.window)
self.cpp_score_entry.grid(row=3, column=1)
python_score_label = tk.Label(self.window, text="Python成绩")
python_score_label.grid(row=4, column=0)
self.python_score_entry = tk.Entry(self.window)
self.python_score_entry.grid(row=4, column=1)
add_student_button = tk.Button(self.window, text="添加学生", command=self.add_student)
add_student_button.grid(row=5, column=0)
show_students_button = tk.Button(self.window, text="显示学生信息", command=self.show_students)
show_students_button.grid(row=5, column=1)
sort_students_button = tk.Button(self.window, text="按总分排序", command=self.sort_students)
sort_students_button.grid(row=6, column=0)
self.students_listbox = tk.Listbox(self.window)
self.students_listbox.grid(row=7, column=0, columnspan=2)
tk.mainloop()
def add_student(self):
sno = self.sno_entry.get()
name = self.name_entry.get()
c_score = self.c_score_entry.get()
cpp_score = self.cpp_score_entry.get()
python_score = self.python_score_entry.get()
if not sno or not name or not c_score or not cpp_score or not python_score:
messagebox.showerror("错误", "所有字段都不能为空")
return
try:
c_score = int(c_score)
cpp_score = int(cpp_score)
python_score = int(python_score)
except ValueError:
messagebox.showerror("错误", "成绩必须为整数")
return
student = Student(sno, name, c_score, cpp_score, python_score)
self.students.append(student)
messagebox.showinfo("成功", "添加学生成功")
def show_students(self):
self.students_listbox.delete(0, tk.END)
for student in self.students:
self.students_listbox.insert(tk.END, f"{student.sno} {student.name} {student.c_score} {student.cpp_score} {student.python_score} {student.total_score}")
def sort_students(self):
self.students.sort(key=lambda student: student.total_score, reverse=True)
messagebox.showinfo("成功", "按总分排序成功")
```
该程序使用了tkinter库实现GUI界面。其中,Student类表示一个学生对象,包含学号、姓名、C成绩、C++成绩、Python成绩和总分属性。StudentManagementSystem类表示学生成绩管理系统,包含添加学生、显示学生信息、按总分排序等功能。在程序中,我们使用了Entry、Button、Label、Listbox等控件来实现界面。当用户点击添加学生按钮时,程序会获取用户输入的信息,创建一个Student对象,并将其添加到学生列表中;当用户点击显示学生信息按钮时,程序会遍历学生列表,并将每个学生的信息显示在Listbox中;当用户点击按总分排序按钮时,程序会按照学生总分进行降序排序,并在弹窗中显示排序成功的消息。
希望这份代码可以帮助你完成学生成绩管理系统的开发。
阅读全文