成绩管理系统,未完成,明天继续
import pymysql
from tkinterimport *
db=pymysql.Connect(host='localhost',port=3306,user='root',passwd='4758stuv870399',db='stuadm',charset='utf8')
cursor=db.cursor()
def showTheTable(Listbox):
Listbox.delete(0,END)
data=[]
sql1= "SELECT * FROM studentadm_information"#构造sql语句
cursor.execute(sql1) # 获取原始语文成绩
all_data=cursor.fetchall()
for iin all_data:
dd=i[0]+str(i[1])+i[2]
Listbox.insert(END,dd)
def updateTheTable():#更新,获取数据,执行sql 更新表单
var1=entry1.get()
var2=int(entry2.get())
var3=entry3.get()
sql= "INSERT INTO studentadm_information values\
('%s',%d,'%s')" % (var1,var2,var3)
print(sql)
try:
cursor.execute(sql) # 没有异常提交数据,
db.commit()
print("学生信息提交成功!")
except:
print("上传信息失败!")
db.rollback()
showTheTable(mylist)
def changeTheTable():#构造sql 删除
var1=entrya.get()
var2=int(entryb.get())
var3=entryc.get()
try:
sql3= "UPDATE studentadm_information set student_name=\'%s\',student_phoneNumber=%s WHERE student_id=%d" % (var1, var3, var2)
print(sql3)
cursor.execute(sql3)
db.commit()
except:
db.rollback()
showTheTable(mylist)
def deleteTheTable():
var1=int(entryp.get())
sql= "DELETE FROM studentadm_information where student_id=%d" % (var1)
try:
cursor.execute(sql)
db.commit()
print("删除成功")
except:
db.rollback()
showTheTable(mylist)
def checkTheTable():
var1= int(entryA.get())
sql1= "SELECT * FROM studentadm_information where student_id=%d" % (var1);
try:
cursor.execute(sql1)
s= cursor.fetchone()
print(s)
if s== None:
print("该学生不存在!")
db.commit()
var2=s[1]
var3=s[2]
entryB.setvar(var2)
entryC.setvar(var3)
except:
db.rollback()
showTheTable(mylist)
window=Tk()
window.geometry("700x500")#主窗口
top=Frame(window,height=200,width=600,bg='green');#显示学生信息
scrollar= Scrollbar(top)
scrollar.pack(side=RIGHT, fill=Y)
mylist=Listbox(top,height=10,width=50,yscrollcommand=scrollar.set)#绑定下拉事件
entry1=Entry(window)#1,2,3是增加按钮
entry2=Entry(window)
entry3=Entry(window)
entrya=Entry(window)#abc是改动的
entryb=Entry(window)
entryc=Entry(window)
entryA=Entry(window)#ABC是查看的
entryB=Entry(window)
entryC=Entry(window)
entryp=Entry(window)#p是用来指定删除对象的
entry1.place(x=50,y=300)
entry2.place(x=200,y=300)
entry3.place(x=350,y=300)
entrya.place(x=50,y=340)
entryb.place(x=200,y=340)
entryc.place(x=350,y=340)
entryA.place(x=50,y=450)
entryB.place(x=250,y=450)
entryC.place(x=450,y=450)
entryp.place(x=350,y=380)
bt1=Button(window,text="增加",command=updateTheTable)
bt1.place(x=520,y=290)
bt2=Button(window,text="改动",command=changeTheTable)
bt2.place(x=520,y=330)
bt3=Button(window,text="删除",command=deleteTheTable)
bt3.place(x=520,y=370)
bt4=Button(window,text="查看",command=checkTheTable)
bt4.place(x=200,y=450)
showTheTable(mylist)
scrollar.config(command=mylist.yview)
mylist.pack(side=LEFT)
top.pack()
window.mainloop()