用Python tkinter库和sqlite3库编写一个学生信息管理系统(其中学生管理系统中含有学生姓名,学号,年龄,QQ号,成绩,专业,班级) 注意:在代码后面添加相应的中文注释
时间: 2024-06-10 20:06:04 浏览: 94
好的,我明白了。以下是代码和注释:
```python
import tkinter as tk
import sqlite3
# 创建GUI窗口
window = tk.Tk()
window.title('学生信息管理系统')
window.geometry('600x400')
# 连接数据库
conn = sqlite3.connect('student.db')
c = conn.cursor()
# 创建学生信息表
c.execute('''CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
student_id TEXT,
age INTEGER,
qq TEXT,
score INTEGER,
major TEXT,
class TEXT
)''')
conn.commit()
# 添加学生信息函数
def add_student():
name = name_entry.get()
student_id = student_id_entry.get()
age = age_entry.get()
qq = qq_entry.get()
score = score_entry.get()
major = major_entry.get()
_class = class_entry.get()
c.execute('INSERT INTO students (name, student_id, age, qq, score, major, class) VALUES (?, ?, ?, ?, ?, ?, ?)',
(name, student_id, age, qq, score, major, _class))
conn.commit()
refresh_students()
# 刷新学生信息函数
def refresh_students():
students_list.delete(0, tk.END)
for row in c.execute('SELECT * FROM students'):
students_list.insert(tk.END, row)
# 创建添加学生信息界面
add_frame = tk.Frame(window)
add_frame.pack(side=tk.LEFT, padx=50)
name_label = tk.Label(add_frame, text='姓名:')
name_label.pack()
name_entry = tk.Entry(add_frame)
name_entry.pack()
student_id_label = tk.Label(add_frame, text='学号:')
student_id_label.pack()
student_id_entry = tk.Entry(add_frame)
student_id_entry.pack()
age_label = tk.Label(add_frame, text='年龄:')
age_label.pack()
age_entry = tk.Entry(add_frame)
age_entry.pack()
qq_label = tk.Label(add_frame, text='QQ号:')
qq_label.pack()
qq_entry = tk.Entry(add_frame)
qq_entry.pack()
score_label = tk.Label(add_frame, text='成绩:')
score_label.pack()
score_entry = tk.Entry(add_frame)
score_entry.pack()
major_label = tk.Label(add_frame, text='专业:')
major_label.pack()
major_entry = tk.Entry(add_frame)
major_entry.pack()
class_label = tk.Label(add_frame, text='班级:')
class_label.pack()
class_entry = tk.Entry(add_frame)
class_entry.pack()
add_button = tk.Button(add_frame, text='添加', command=add_student)
add_button.pack()
# 创建展示学生信息界面
show_frame = tk.Frame(window)
show_frame.pack(side=tk.LEFT, padx=50)
students_list = tk.Listbox(show_frame)
students_list.pack()
refresh_button = tk.Button(show_frame, text='刷新', command=refresh_students)
refresh_button.pack()
# 执行主循环
window.mainloop()
# 关闭数据库连接
conn.close()
```
中文注释已添加在代码中,希望能够帮到您!
阅读全文