2019-06-04

成績管理系統(tǒng),未完成,明天繼續(xù)

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"#構(gòu)造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():#更新,獲取數(shù)據(jù),執(zhí)行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)? # 沒有異常提交數(shù)據(jù),

? ? ? ? db.commit()

? ? ? ? print("學(xué)生信息提交成功!")

? ? except:

? ? ? ? print("上傳信息失??!")

? ? ? ? db.rollback()

? ? showTheTable(mylist)

def changeTheTable():#構(gòu)造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("該學(xué)生不存在!")

? ? ? ? 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');#顯示學(xué)生信息

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()

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容