python学生学籍管理系统gui代码
时间: 2024-06-08 10:03:19 浏览: 244
Python 学生学籍管理系统 GUI 代码是基于 Python 语言和 Tkinter 模块开发的,可以实现对学生信息进行增、删、改、查等操作。以下是一个简单的 Python 学生学籍管理系统 GUI 代码示例:
```
from tkinter import *
import tkinter.messagebox as messagebox
class Student:
def __init__(self, name, age, gender, major):
self.name = name
self.age = age
self.gender = gender
self.major = major
class StudentManagementSystem:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def remove_student(self, student):
self.students.remove(student)
def update_student(self, old_student, new_student):
index = self.students.index(old_student)
self.students[index] = new_student
def search_student(self, name):
for student in self.students:
if student.name == name:
return student
return None
class StudentManagementGUI:
def __init__(self):
self.system = StudentManagementSystem()
self.window = Tk()
self.window.title("学生学籍管理系统")
self.name_label = Label(self.window, text="姓名:")
self.name_label.grid(row=0, column=0)
self.name_entry = Entry(self.window)
self.name_entry.grid(row=0, column=1)
self.age_label = Label(self.window, text="年龄:")
self.age_label.grid(row=1, column=0)
self.age_entry = Entry(self.window)
self.age_entry.grid(row=1, column=1)
self.gender_label = Label(self.window, text="性别:")
self.gender_label.grid(row=2, column=0)
self.gender_entry = Entry(self.window)
self.gender_entry.grid(row=2, column=1)
self.major_label = Label(self.window, text="专业:")
self.major_label.grid(row=3, column=0)
self.major_entry = Entry(self.window)
self.major_entry.grid(row=3, column=1)
self.add_button = Button(self.window, text="添加", command=self.add_student)
self.add_button.grid(row=4, column=0)
self.remove_button = Button(self.window, text="删除", command=self.remove_student)
self.remove_button.grid(row=4, column=1)
self.update_button = Button(self.window, text="修改", command=self.update_student)
self.update_button.grid(row=5, column=0)
self.search_button = Button(self.window, text="查询", command=self.search_student)
self.search_button.grid(row=5, column=1)
def add_student(self):
name = self.name_entry.get()
age = int(self.age_entry.get())
gender = self.gender_entry.get()
major = self.major_entry.get()
student = Student(name, age, gender, major)
self.system.add_student(student)
def remove_student(self):
name = self.name_entry.get()
student = self.system.search_student(name)
if student is not None:
self.system.remove_student(student)
def update_student(self):
name = self.name_entry.get()
age = int(self.age_entry.get())
gender = self.gender_entry.get()
major = self.major_entry.get()
old_student = self.system.search_student(name)
new_student = Student(name, age, gender, major)
if old_student is not None:
self.system.update_student(old_student, new_student)
def search_student(self):
name = self.name_entry.get()
student = self.system.search_student(name)
if student is not None:
messagebox.showinfo("查询结果", f"姓名:{student.name}\n年龄:{student.age}\n性别:{student.gender}\n专业:{student.major}")
else:
messagebox.showinfo("查询结果", "没有找到该学生")
def run(self):
self.window.mainloop()
if __name__ == "__main__":
gui = StudentManagementGUI()
gui.run()
```
阅读全文