[Python急救站]含义GUI的学生管理系统
这个管理系统是含有GUI界面的学生管理系统,比较方便。
import tkinter as tk
class Student:
def __init__(self, name, student_id, score):
self.name = name
self.student_id = student_id
self.score = score
class StudentManager:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def find_student(self, student_id):
for student in self.students:
if student.student_id == student_id:
return student
return None
def update_student_score(self, student_id, new_score):
student = self.find_student(student_id)
if student:
student.score = new_score
return True
return False
def add_student():
name = name_entry.get()
student_id = student_id_entry.get()
score = float(score_entry.get())
student = Student(name, student_id, score)
manager.add_student(student)
result_label.config(text="学生成绩录入成功")
def find_student():
student_id = student_id_entry.get()
student = manager.find_student(student_id)
if student:
result_label.config(text="学生姓名:" + student.name + ",学生成绩:" + str(student.score))
else:
result_label.config(text="未找到该学生")
def update_student_score():
student_id = student_id_entry.get()
new_score = float(score_entry.get())
if manager.update_student_score(student_id, new_score):
result_label.config(text="成绩修改成功")
else:
result_label.config(text="未找到该学生")
# 创建学生管理对象
manager = StudentManager()
# 创建GUI窗口
window = tk.Tk()
window.title("学生成绩查询系统")
# 创建GUI组件
name_label = tk.Label(window, text="学生姓名:")
name_label.pack()
name_entry = tk.Entry(window)
name_entry.pack()
student_id_label = tk.Label(window, text="学生学号:")
student_id_label.pack()
student_id_entry = tk.Entry(window)
student_id_entry.pack()
score_label = tk.Label(window, text="学生成绩:")
score_label.pack()
score_entry = tk.Entry(window)
score_entry.pack()
add_button = tk.Button(window, text="录入学生成绩", command=add_student)
add_button.pack()
find_button = tk.Button(window, text="查找学生成绩", command=find_student)
find_button.pack()
update_button = tk.Button(window, text="修改学生成绩", command=update_student_score)
update_button.pack()
result_label = tk.Label(window, text="")
result_label.pack()
# 运行GUI窗口
window.mainloop()
运行结果如下: