phython窗口编程,学生信息管理系统,第一行为姓名,输入框,查找按钮,点击后弹出查找的学生信息(姓名,学号,性别),第二行为学号,对话框,第三行为籍贯,下拉式选项,选择内容为中国的省,第四行为年级,下拉式选项,范围为大一到大四,班级,可选式对话框,第五行为性别,可选式对话框,第六行为是否为班长,可选式对话框,增加按钮,删除按钮,点击添加按钮后将所填写的信息显示在底部的显示框中,窗口右下角显示学生照片,
时间: 2023-08-05 11:07:29 浏览: 146
以下是一个简单的Python窗口编程实现学生信息管理系统的示例代码:
```python
import tkinter as tk
class Student:
def __init__(self, name, number, gender, hometown, grade, class_, is_leader):
self.name = name
self.number = number
self.gender = gender
self.hometown = hometown
self.grade = grade
self.class_ = class_
self.is_leader = is_leader
class StudentInfoGUI:
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.number_label = tk.Label(master, text="学号")
self.number_label.grid(row=1, column=0)
self.number_text = tk.StringVar()
self.number_entry = tk.Entry(master, textvariable=self.number_text)
self.number_entry.grid(row=1, column=1)
# 籍贯
self.hometown_label = tk.Label(master, text="籍贯")
self.hometown_label.grid(row=2, column=0)
self.hometown_options = ["北京", "上海", "广东", "江苏", "浙江"]
self.hometown_var = tk.StringVar()
self.hometown_var.set(self.hometown_options[0])
self.hometown_menu = tk.OptionMenu(master, self.hometown_var, *self.hometown_options)
self.hometown_menu.grid(row=2, column=1)
# 年级、班级
self.grade_label = tk.Label(master, text="年级")
self.grade_label.grid(row=3, column=0)
self.grade_options = ["大一", "大二", "大三", "大四"]
self.grade_var = tk.StringVar()
self.grade_var.set(self.grade_options[0])
self.grade_menu = tk.OptionMenu(master, self.grade_var, *self.grade_options)
self.grade_menu.grid(row=3, column=1)
self.class_label = tk.Label(master, text="班级")
self.class_label.grid(row=3, column=2)
self.class_entry = tk.Entry(master)
self.class_entry.grid(row=3, column=3)
# 性别、是否为班长
self.gender_label = tk.Label(master, text="性别")
self.gender_label.grid(row=4, column=0)
self.gender_options = ["男", "女"]
self.gender_var = tk.StringVar()
self.gender_var.set(self.gender_options[0])
self.gender_menu = tk.OptionMenu(master, self.gender_var, *self.gender_options)
self.gender_menu.grid(row=4, column=1)
self.is_leader_label = tk.Label(master, text="是否为班长")
self.is_leader_label.grid(row=4, column=2)
self.is_leader_var = tk.BooleanVar()
self.is_leader_var.set(False)
self.is_leader_checkbox = tk.Checkbutton(master, variable=self.is_leader_var)
self.is_leader_checkbox.grid(row=4, column=3)
# 增加按钮、删除按钮
self.add_button = tk.Button(master, text="增加", command=self.add_student)
self.add_button.grid(row=5, column=1)
self.delete_button = tk.Button(master, text="删除", command=self.delete_student)
self.delete_button.grid(row=5, column=2)
# 显示框
self.display_text = tk.Text(master, height=10)
self.display_text.grid(row=6, column=0, columnspan=4)
# 学生照片
self.photo_label = tk.Label(master, text="学生照片")
self.photo_label.grid(row=7, column=0)
def add_student(self):
name = self.name_entry.get()
number = self.number_entry.get()
gender = self.gender_var.get()
hometown = self.hometown_var.get()
grade = self.grade_var.get()
class_ = self.class_entry.get()
is_leader = self.is_leader_var.get()
student = Student(name, number, gender, hometown, grade, class_, is_leader)
self.display_text.insert(tk.END, f"{student.name} {student.number} {student.gender} {student.hometown} {student.grade} {student.class_} {student.is_leader}\n")
def delete_student(self):
self.display_text.delete('1.0', tk.END)
root = tk.Tk()
my_gui = StudentInfoGUI(root)
root.mainloop()
```
这个程序中,我们使用了Tkinter模块来创建一个GUI窗口,并设计了各种GUI组件来实现学生信息管理系统。在GUI中,用户可以填写学生的姓名、学号、籍贯、年级、班级、性别和是否为班长等信息,并通过“增加”按钮将这些信息添加到显示框中。用户还可以通过“删除”按钮清空显示框中的所有信息。在窗口右下角,我们还添加了一个标签来显示学生的照片。当然,这个程序只是一个简单的示例,如果你想要实现更复杂的学生信息管理系统,你需要进一步学习Python GUI编程的知识。
阅读全文