当前程序只是简单实现,还缺后台很多功能!! 废话不多说,直接上源码!!! import tkinter as tk from tkinter import messagebox window = tk.Tk() window.title("学生信息管理系统") window.geometry("500x650") # 学生管理系统 class StudentSystem: root: None def __init__(self): self.root = None self.student_list = [] # 创建界面 self.interface() # 创建界面 def interface(self): # 创建姓名输入框 name_label = tk.Label(window, text="姓名:") name_label.place(x=180, y=50) self.name_entry = tk.Entry(window) self.name_entry.place(x=230, y=50) # 创建性别输入框 gender_label = tk.Label(window, text="性别:") gender_label.place(x=180, y=100) self.gender_entry = tk.Entry(window) self.gender_entry.place(x=230, y=100) # 创建手机号输入框 phone_label = tk.Label(window, text="手机号:") phone_label.place(x=180, y=150) self.phone_entry = tk.Entry(window) self.phone_entry.place(x=230, y=150) # 添加按钮 tk.Button(window, text="添加", width=8, relief="solid", command=self.add_student).place(x=100, y=200) # 删除按钮 tk.Button(window, text="删除", width=8, relief="solid", command=self.del_student).place(x=200, y=200) # 修改按钮 tk.Button(window, text="修改", width=8, relief="solid", command=self.modify_student).place(x=300, y=200) # 显示按钮 tk.Button(window, text="显示", width=8, relief="solid", command=self.show_student).place(x=400, y=200) # 文字 tk.Label(window, text="xxxx级软件工程x班 xxx").place(x=180, y=250) self.info_text = tk.Text(window) self.info_text.place(x=0, y=280) # 学生信息类 class Student: def __init__(self, name, gender, tel): self.name = name self.gender = gender self.tel = tel # 检查输入是否为空 def is_input_empty(self, entry): return len(entry.get()) == 0 # 添加学生 def add_student(self): if self.is_input_empty(self.name_entry) or self.is_input_empty(self.gender_entry) or self.is_input_empty( self.phone_entry): messagebox.showwarning("警告", "输入不能为空!") return name = self.name_entry.get() gender = self.gender_entry.get() phone = self.phone_entry.get() student = self.Student(name, gender, phone) self.student_list.append(student) self.name_entry.delete(0, tk.END) self.gender_entry.delete(0, tk.END) self.phone_entry.delete(0, tk.END) self.info_text.insert(tk.END, f"添加学生:\n姓名:{name}\n性别:{gender}\n手机号:{phone}\n\n") # 删除学生 def del_student(self): if self.is_input_empty(self.name_entry): messagebox.showwarning("警告", "请输入学生姓名!") return name = self.name_entry.get() for student in self.student_list: if student.name == name: self.student_list.remove(student) self.info_text.insert(tk.END, f"删除学生:\n姓名:{student.name}\n性别:{student.gender}\n手机号:{student.tel}\n\n") break self.name_entry.delete(0, tk.END) # 修改学生 def modify_student(self): if self.is_input_empty(self.name_entry): messagebox.showwarning("警告", "请输入学生姓名!") return name = self.name_entry.get() gender = self.gender_entry.get() phone = self.phone_entry.get() for student in self.student_list: if student.name == name: student.gender = gender student.tel = phone self.info_text.insert(tk.END, f"修改学生:\n姓名:{student.name}\n性别:{student.gender}\n手机号:{student.tel}\n\n") break self.name_entry.delete(0, tk.END) self.gender_entry.delete(0, tk.END) self.phone_entry.delete(0, tk.END) # 显示学生 def show_student(self): self.info_text.delete(1.0, tk.END) # 清空文本框内容 if len(self.student_list) == 0: self.info_text.insert(tk.END, "学生列表为空!") else: self.info_text.insert(tk.END, "学生列表:\n") for student in self.student_list: self.info_text.insert(tk.END, f"姓名:{student.name}\n性别:{student.gender}\n手机号:{student.tel}\n\n") if __name__ == "__main__": app = StudentSystem() window.mainloop()
使用Python tkinter库编写GUI程序,实现简单学生信息管理系统的设计。
于 2023-06-28 17:26:31 首次发布