python学生信息管理系统界面代码
时间: 2023-07-22 17:38:55 浏览: 189
以下是一个简单的Python学生信息管理系统的界面代码示例:
```python
from tkinter import *
import tkinter.messagebox as messagebox
class Student:
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
class StudentManagementSystem:
def __init__(self):
self.students = []
self.window = Tk()
self.window.title("学生信息管理系统")
self.window.geometry("400x300")
self.name_label = Label(self.window, text="姓名:")
self.name_label.place(x=50, y=50)
self.name_entry = Entry(self.window)
self.name_entry.place(x=100, y=50)
self.age_label = Label(self.window, text="年龄:")
self.age_label.place(x=50, y=100)
self.age_entry = Entry(self.window)
self.age_entry.place(x=100, y=100)
self.gender_label = Label(self.window, text="性别:")
self.gender_label.place(x=50, y=150)
self.gender_entry = Entry(self.window)
self.gender_entry.place(x=100, y=150)
self.add_button = Button(self.window, text="添加", command=self.add_student)
self.add_button.place(x=50, y=200)
self.show_button = Button(self.window, text="显示", command=self.show_students)
self.show_button.place(x=150, y=200)
self.clear_button = Button(self.window, text="清空", command=self.clear_input)
self.clear_button.place(x=250, y=200)
self.window.mainloop()
def add_student(self):
name = self.name_entry.get()
age = self.age_entry.get()
gender = self.gender_entry.get()
if name and age and gender:
student = Student(name, age, gender)
self.students.append(student)
messagebox.showinfo("添加成功", "添加学生信息成功!")
else:
messagebox.showwarning("添加失败", "请填写完整的学生信息!")
def show_students(self):
if self.students:
for index, student in enumerate(self.students):
messagebox.showinfo(f"学生{index+1}信息", f"姓名:{student.name}\n年龄:{student.age}\n性别:{student.gender}")
else:
messagebox.showwarning("未找到学生信息", "暂时没有学生信息!")
def clear_input(self):
self.name_entry.delete(0, END)
self.age_entry.delete(0, END)
self.gender_entry.delete(0, END)
if __name__ == "__main__":
system = StudentManagementSystem()
```
这个界面代码实现了一个简单的学生信息管理系统,可以添加学生、显示学生信息和清空输入框。你可以根据自己的需求进行修改和扩展。
阅读全文