用GUI写学生管理系统
时间: 2024-06-14 16:03:55 浏览: 18
以下是一个用GUI编写的学生管理系统的示例:
```python
import tkinter as tk
from tkinter import messagebox
class Student:
def __init__(self, name, age, grade):
self.name = name
self.age = age
self.grade = grade
class StudentManagementSystemGUI:
def __init__(self):
self.students = []
self.window = tk.Tk()
self.window.title("学生管理系统")
self.name_label = tk.Label(self.window, text="姓名:")
self.name_label.pack()
self.name_entry = tk.Entry(self.window)
self.name_entry.pack()
self.age_label = tk.Label(self.window, text="年龄:")
self.age_label.pack()
self.age_entry = tk.Entry(self.window)
self.age_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.show_button = tk.Button(self.window, text="显示学生", command=self.show_students)
self.show_button.pack()
def add_student(self):
name = self.name_entry.get()
age = self.age_entry.get()
grade = self.grade_entry.get()
student = Student(name, age, grade)
self.students.append(student)
messagebox.showinfo("提示", "学生添加成功!")
self.name_entry.delete(0, tk.END)
self.age_entry.delete(0, tk.END)
self.grade_entry.delete(0, tk.END)
def show_students(self):
if len(self.students) == 0:
messagebox.showinfo("提示", "暂无学生信息!")
else:
student_info = ""
for student in self.students:
student_info += f"姓名:{student.name},龄:{student.age},年级:{student.grade}\n"
messagebox.showinfo("学生信息", student_info)
def run(self):
self.window.mainloop()
if __name__ == "__main__":
system = StudentManagementSystemGUI()
system.run()
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)