请制作一个thinker 界面学生管理系统 Python
时间: 2024-03-02 11:49:38 浏览: 150
好的,以下是一个简单的思考者界面学生管理系统Python代码示例:
```python
import tkinter as tk
class Student:
def __init__(self, name, grade):
self.name = name
self.grade = grade
class StudentManagementSystem:
def __init__(self):
self.students = []
def add_student(self, name, grade):
student = Student(name, grade)
self.students.append(student)
def remove_student(self, student):
self.students.remove(student)
def get_student_by_name(self, name):
for student in self.students:
if student.name == name:
return student
def get_all_students(self):
return self.students
class App:
def __init__(self):
self.window = tk.Tk()
self.window.title("学生管理系统")
self.system = StudentManagementSystem()
self.name_label = tk.Label(self.window, text="姓名:")
self.name_label.pack()
self.name_entry = tk.Entry(self.window)
self.name_entry.pack()
self.grade_label = tk.Label(self.window, text="年级:")
self.grade_label.pack()
self.grade_entry = tk.Entry(self.window)
self.grade_entry.pack()
self.add_button = tk.Button(self.window, text="添加学生", command=self.add_student)
self.add_button.pack()
self.remove_button = tk.Button(self.window, text="删除学生", command=self.remove_student)
self.remove_button.pack()
self.search_button = tk.Button(self.window, text="搜索学生", command=self.search_student)
self.search_button.pack()
self.show_all_button = tk.Button(self.window, text="显示所有学生", command=self.show_all_students)
self.show_all_button.pack()
self.result_label = tk.Label(self.window, text="")
self.result_label.pack()
def add_student(self):
name = self.name_entry.get()
grade = self.grade_entry.get()
self.system.add_student(name, grade)
def remove_student(self):
name = self.name_entry.get()
student = self.system.get_student_by_name(name)
if student:
self.system.remove_student(student)
def search_student(self):
name = self.name_entry.get()
student = self.system.get_student_by_name(name)
if student:
self.result_label.config(text="姓名:{} 年级:{}".format(student.name, student.grade))
else:
self.result_label.config(text="没有找到该学生")
def show_all_students(self):
students = self.system.get_all_students()
if students:
result = ""
for student in students:
result += "姓名:{} 年级:{}\n".format(student.name, student.grade)
self.result_label.config(text=result)
else:
self.result_label.config(text="没有学生")
def run(self):
self.window.mainloop()
if __name__ == "__main__":
app = App()
app.run()
```
这个简单的学生管理系统使用了Tkinter库创建了一个简单的GUI界面,可以添加、删除、搜索和显示所有学生。
阅读全文