parent
f3e3989819
commit
f03f362820
@ -0,0 +1,98 @@
|
||||
import tkinter as tk
|
||||
import pymysql
|
||||
|
||||
# 连接到MySQL数据库
|
||||
db = pymysql.connect(
|
||||
host="localhost",
|
||||
user="root",
|
||||
password="passwd",
|
||||
database="jzw_text"
|
||||
)
|
||||
cursor = db.cursor()
|
||||
|
||||
# 添加学员信息
|
||||
def add_student():
|
||||
name = name_entry.get()
|
||||
sex = sex_entry.get()
|
||||
tel = tel_entry.get()
|
||||
sql = "insert into xs (name, sex, tel) values (%s, %s, %s)"
|
||||
val = (name, sex, tel)
|
||||
cursor.execute(sql, val)
|
||||
db.commit()
|
||||
|
||||
# 删除学员信息
|
||||
def delete_student():
|
||||
name = name_entry.get()
|
||||
sql = "delete from xs where name = %s"
|
||||
val = (name,)
|
||||
cursor.execute(sql, val)
|
||||
db.commit()
|
||||
|
||||
# 修改学员信息
|
||||
def update_student():
|
||||
name = name_entry.get()
|
||||
sex = sex_entry.get()
|
||||
tel = tel_entry.get()
|
||||
sql = "update xs set sex = %s, tel = %s where name = %s"
|
||||
val = (sex, tel, name)
|
||||
cursor.execute(sql, val)
|
||||
db.commit()
|
||||
|
||||
# 查询学员信息
|
||||
def search_student():
|
||||
name = name_entry.get()
|
||||
sql = "select * from xs where name = %s"
|
||||
val = (name,)
|
||||
cursor.execute(sql, val)
|
||||
result = cursor.fetchall()
|
||||
if result:
|
||||
for row in result:
|
||||
print("姓名:{},性别:{},电话:{}".format(row[0],row[1],row[2]))
|
||||
else:
|
||||
print("学生没有找到")
|
||||
|
||||
# 显示学员信息
|
||||
def show_students():
|
||||
cursor.execute("SELECT * FROM xs")
|
||||
result = cursor.fetchall()
|
||||
if result:
|
||||
for row in result:
|
||||
print("姓名:{},性别:{},电话:{}".format(row[0],row[1],row[2]))
|
||||
else:
|
||||
print("没有学生信息")
|
||||
|
||||
# 创建GUI界面
|
||||
window = tk.Tk()
|
||||
window.title("学生信息管理系统")
|
||||
|
||||
name_label = tk.Label(window, text="姓名")
|
||||
name_label.pack()
|
||||
name_entry = tk.Entry(window)
|
||||
name_entry.pack()
|
||||
|
||||
sex_label = tk.Label(window, text="性别")
|
||||
sex_label.pack()
|
||||
sex_entry = tk.Entry(window)
|
||||
sex_entry.pack()
|
||||
|
||||
tel_label = tk.Label(window, text="电话")
|
||||
tel_label.pack()
|
||||
tel_entry = tk.Entry(window)
|
||||
tel_entry.pack()
|
||||
|
||||
add_button = tk.Button(window, text="添加", command=add_student)
|
||||
add_button.pack()
|
||||
|
||||
delete_button = tk.Button(window, text="删除", command=delete_student)
|
||||
delete_button.pack()
|
||||
|
||||
update_button = tk.Button(window, text="修改", command=update_student)
|
||||
update_button.pack()
|
||||
|
||||
search_button = tk.Button(window, text="查询", command=search_student)
|
||||
search_button.pack()
|
||||
|
||||
show_button = tk.Button(window, text="显示学员信息", command=show_students)
|
||||
show_button.pack()
|
||||
|
||||
window.mainloop()
|
Loading…
Reference in new issue