import pymysql
import tkinter as tk
import tkinter.messagebox
db = pymysql.connect(host='localhost', port=3306, user='root', password='123', database='pyproject')
#db=pymysql.connect('localhost','root','123','pyproject',charset='utf8')
cursor=db.cursor()
def IsExists(id):
sql="select * from students where id=%s"
cursor.execute(sql,id)
result=cursor.rowcount
if result:
return True
else:
return False
def Add(id,name,age,email):
if(IsExists(id)==True):
print('该学生已存在')
tk.messagebox.showwarning('提示','该学生已存在')
else:
sql="insert into students values(%s,%s,%s,%s)"
cursor.execute(sql,(id,name,age,email))
result=cursor.rowcount
if result:
print('添加成功')
tk.messagebox.showinfo('提示','添加成功!')
else:
print('添加失败')
tk.messagebox.showerror('提示','添加失败!')
def Delete(id):
if(IsExists(id)==True):
sql="delete from students where id=%s"
cursor.execute(sql,id)
result=cursor.rowcount
if result:
print('删除成功')
tk.messagebox.showinfo('提示','删除成功!')
else:
print('删除失败')
tk.messagebox.showerror('提示','删除失败!')
else:
print('该学生不存在')
tk.messagebox.showwarning('提示','该学生不存在!')
def Update(id,name,age,eamil):
if(IsExists(id)==True):
sql='update students set name=%s,age=%s,email=%s where id=%s'
cursor.execute(sql,(name,age,eamil,id))
result=cursor.rowcount
if result:
print('修改成功')
tk.messagebox.showinfo('提示','修改成功!')
else:
print('修改失败')
tk.messagebox.showerror('提示','修改失败!')
else:
print('未查询到该学生')
tk.messagebox.showwarning('提示','未查询到该学生!')
def Query(id):
sql="select * from students where id =%s"
cursor.execute(sql,id)
result=cursor.fetchone()
print(result)
def QueryAll():
#list=['学号:','姓名:','年龄:','邮件:']
sql="select * from students"
cursor.execute(sql)
result=cursor.fetchall()
#for items in result:
# for index,item in enumerate(items):
# print(list[index],item,end='')
# print('\n')
return result
QueryAll()
python简易学生管理系统
需积分: 0 131 浏览量
2023-07-02
10:23:20
上传
评论
收藏 24KB ZIP 举报
橙余期
- 粉丝: 36
- 资源: 1
最新资源
- n.cpp
- jdk-8u411-windows-x64下载安装可用
- vgg模型-图像分类算法对水果识别-不含数据集图片-含逐行注释和说明文档.zip
- KMP算法(Knuth-Morris-Pratt算法
- vgg模型-python语言pytorch框架训练识别化妆品分类-不含数据集图片-含逐行注释和说明文档.zip
- KMP算法(Knuth-Morris-Pratt算法
- shufflenet模型-基于人工智能的卷积网络训练识别狗的表情-不含数据集图片-含逐行注释和说明文档.zip
- shufflenet模型-python语言pytorch框架训练识别张嘴闭嘴-不含数据集图片-含逐行注释和说明文档.zip
- resnet模型-基于人工智能的卷积网络训练识别面部表情识别-不含数据集图片-含逐行注释和说明文档
- resnet模型-python语言pytorch框架训练识别香蕉品质-不含数据集图片-含逐行注释和说明文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈