python学生信息管理系统tkinter
时间: 2023-12-12 12:35:04 浏览: 157
以下是一个简单的Python学生信息管理系统的Tkinter界面实现,包括添加、删除、修改和查询学生信息的功能:
```python
import tkinter as tk
class Student:
def __init__(self, name, id, course, score):
self.name = name
self.id = id
self.course = course
self.score = score
class StudentManagementSystem:
def __init__(self):
self.students = []
def add_student(self, name, id, course, score):
student = Student(name, id, course, score)
self.students.append(student)
def delete_student(self, id):
for student in self.students:
if student.id == id:
self.students.remove(student)
def update_student(self, id, name, course, score):
for student in self.students:
if student.id == id:
student.name = name
student.course = course
student.score = score
def search_student(self, id):
for student in self.students:
if student.id == id:
return student
return None
class StudentManagementSystemGUI:
def __init__(self):
self.system = StudentManagementSystem()
self.window = tk.Tk()
self.window.title("学生信息管理系统")
self.window.geometry("400x300")
self.name_label = tk.Label(self.window, text="姓名")
self.name_label.grid(row=0, column=0)
self.name_entry = tk.Entry(self.window)
self.name_entry.grid(row=0, column=1)
self.id_label = tk.Label(self.window, text="学号")
self.id_label.grid(row=1, column=0)
self.id_entry = tk.Entry(self.window)
self.id_entry.grid(row=1, column=1)
self.course_label = tk.Label(self.window, text="课程")
self.course_label.grid(row=2, column=0)
self.course_entry = tk.Entry(self.window)
self.course_entry.grid(row=2, column=1)
self.score_label = tk.Label(self.window, text="成绩")
self.score_label.grid(row=3, column=0)
self.score_entry = tk.Entry(self.window)
self.score_entry.grid(row=3, column=1)
self.add_button = tk.Button(self.window, text="添加", command=self.add_student)
self.add_button.grid(row=4, column=0)
self.delete_button = tk.Button(self.window, text="删除", command=self.delete_student)
self.delete_button.grid(row=4, column=1)
self.update_button = tk.Button(self.window, text="修改", command=self.update_student)
self.update_button.grid(row=4, column=2)
self.search_button = tk.Button(self.window, text="查询", command=self.search_student)
self.search_button.grid(row=4, column=3)
self.result_label = tk.Label(self.window, text="")
self.result_label.grid(row=5, column=0, columnspan=4)
self.window.mainloop()
def add_student(self):
name = self.name_entry.get()
id = self.id_entry.get()
course = self.course_entry.get()
score = self.score_entry.get()
self.system.add_student(name, id, course, score)
self.result_label.config(text="添加成功")
def delete_student(self):
id = self.id_entry.get()
self.system.delete_student(id)
self.result_label.config(text="删除成功")
def update_student(self):
id = self.id_entry.get()
name = self.name_entry.get()
course = self.course_entry.get()
score = self.score_entry.get()
self.system.update_student(id, name, course, score)
self.result_label.config(text="修改成功")
def search_student(self):
id = self.id_entry.get()
student = self.system.search_student(id)
if student:
self.name_entry.delete(0, tk.END)
self.name_entry.insert(0, student.name)
self.course_entry.delete(0, tk.END)
self.course_entry.insert(0, student.course)
self.score_entry.delete(0, tk.END)
self.score_entry.insert(0, student.score)
self.result_label.config(text="")
else:
self.result_label.config(text="未找到该学生")
if __name__ == "__main__":
gui = StudentManagementSystemGUI()
```
阅读全文