学生信息管理系统tkinter
时间: 2023-12-14 08:05:35 浏览: 100
以下是一个使用tkinter实现的学生信息管理系统的示例代码:
```python
import tkinter as tk
class Student:
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
class StudentManagementSystem:
def __init__(self, master):
self.master = master
master.title("学生信息管理系统")
# 创建标签和输入框
self.name_label = tk.Label(master, text="姓名:")
self.name_label.grid(row=0, column=0)
self.name_entry = tk.Entry(master)
self.name_entry.grid(row=0, column=1)
self.age_label = tk.Label(master, text="年龄:")
self.age_label.grid(row=1, column=0)
self.age_entry = tk.Entry(master)
self.age_entry.grid(row=1, column=1)
self.gender_label = tk.Label(master, text="性别:")
self.gender_label.grid(row=2, column=0)
self.gender_entry = tk.Entry(master)
self.gender_entry.grid(row=2, column=1)
# 创建按钮
self.add_button = tk.Button(master, text="添加学生", command=self.add_student)
self.add_button.grid(row=3, column=0)
self.show_button = tk.Button(master, text="显示所有学生", command=self.show_students)
self.show_button.grid(row=3, column=1)
# 创建文本框
self.text = tk.Text(master)
self.text.grid(row=4, columnspan=2)
# 学生列表
self.students = []
def add_student(self):
name = self.name_entry.get()
age = self.age_entry.get()
gender = self.gender_entry.get()
student = Student(name, age, gender)
self.students.append(student)
self.text.insert(tk.END, f"添加学生:{name},{age},{gender}\n")
def show_students(self):
self.text.delete(1.0, tk.END)
for i, student in enumerate(self.students):
self.text.insert(tk.END, f"学生{i+1}:\n")
self.text.insert(tk.END, f"姓名:{student.name}\n")
self.text.insert(tk.END, f"年龄:{student.age}\n")
self.text.insert(tk.END, f"性别:{student.gender}\n\n")
root = tk.Tk()
app = StudentManagementSystem(root)
root.mainloop()
```
这个学生信息管理系统包括添加学生和显示所有学生两个功能。用户可以在界面上输入学生的姓名、年龄和性别,然后点击“添加学生”按钮将学生信息添加到学生列表中。用户也可以点击“显示所有学生”按钮来查看所有已添加的学生信息。
阅读全文