




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
python語言程序設(shè)計實驗指導(dǎo)書院(系、部)課程名稱python語言程序設(shè)計授課專業(yè)授課年級授課教師實驗時數(shù)2089年8月填寫要求實驗內(nèi)容應(yīng)編制在授課計劃內(nèi);實驗教學(xué)內(nèi)容中應(yīng)有學(xué)時分配;應(yīng)明確開展時間;每份指導(dǎo)書要求封皮相同,內(nèi)容完整,格式不限;指導(dǎo)書必須經(jīng)由專業(yè)負(fù)責(zé)人審核,并交由系主任審核,教務(wù)辦公室留存?zhèn)浒?;教師實踐指導(dǎo)時需攜帶指導(dǎo)書。學(xué)院教務(wù)辦公室第第頁共19頁實驗名稱:編寫學(xué)生管理系統(tǒng)【實驗?zāi)康摹磕軌蚓唧w應(yīng)用到基本的問題需求解決,具備基本的程序設(shè)計能力。能利用所學(xué)的知識通過編程完成項目的搭建?!緦嶒炂骶摺?.計算機【實驗項目】序號實驗項目類型具體實驗項目名稱備注1綜合性基礎(chǔ)編程內(nèi)容必做編寫學(xué)生管理系統(tǒng)必做思考題選做【管理要求】由班長和學(xué)習(xí)委員將本班學(xué)生按照每組1人.分成若干實驗小組。在實驗實訓(xùn)過程中,注意按時填寫實驗實訓(xùn)記錄表。自覺維護實驗室衛(wèi)生?!緦嶒炓蟆?.提前預(yù)習(xí)實驗指導(dǎo)書和實驗報告的內(nèi)容,復(fù)習(xí)課程所學(xué)過的相關(guān)內(nèi)容,對于沒有理解和掌握的知識點做好記錄。2.帶著問題參加實驗活動,安靜完成實驗過程。3.實驗過程中積極與實驗教學(xué)人員互動,及時解決新問題和老問題。4.實驗過程中及時、正確的做好記錄。5.實驗結(jié)束后,整理好個人物品和相關(guān)物品,保持好環(huán)境衛(wèi)生。6.按照要求完成實驗報告。【實驗內(nèi)容一】簡單的編程練習(xí)習(xí)題練習(xí)1:編寫一個n+1的程序,當(dāng)用戶輸入一個整數(shù)n,則輸出n+1例如:用戶輸入4,則程序輸出5#n=int(input("請輸入一個整數(shù):"))
#print(n+1)習(xí)題練習(xí)2:編寫一個程序,幫助水果店實現(xiàn)計價功能,用戶輸入水果單價(元/kg)和重量(kg),計算出需要花費的金額例:用戶輸入單價3,輸入重量2,輸出6#n1=float(input("請輸入水果價格:"))
#n2=float(input("請輸入水果的重量:"))
#print(n1*n2)
#n1=float(input("請輸入水果單價(元/kg):"))
#n2=float(input("請輸入水果的重量(kg):"))
#price=n1*n2
#print("水果的價格為:",price,"元")【實驗內(nèi)容二】一、需求分析學(xué)生管理系統(tǒng)應(yīng)具備的功能1.添加學(xué)生及成績信息2.將學(xué)生信息保存到文件中3.修改和刪除學(xué)生信息4.查詢學(xué)生信息5.根據(jù)學(xué)生成績進行排序6.統(tǒng)計學(xué)生的總分二、系統(tǒng)功能結(jié)構(gòu)——學(xué)生信息系統(tǒng)的7大模塊1.錄入學(xué)生信息2.查找學(xué)生信息3.刪除學(xué)生信息4.修改學(xué)生信息5.學(xué)生成績排名模塊6.統(tǒng)計學(xué)生總?cè)藬?shù)模塊7.顯示全部學(xué)生信息模塊主界面主界面信息錄入信息查詢信息輸出系統(tǒng)操作退出學(xué)生信息學(xué)號查詢班級查詢班級信息姓名查詢輸出學(xué)生成績權(quán)限修改增加用戶其他用戶登錄總體構(gòu)思其實類似這類信息管理系統(tǒng)之類的程序,核心是和數(shù)據(jù)打交道,包括增刪查改,讀取、展示、保存等。三、功能實現(xiàn)1.引入python標(biāo)準(zhǔn)圖形界面庫tkinter。fromtkinterimport*#導(dǎo)入tkinter模塊所有類root=Tk()#創(chuàng)建主窗口root.geometry('200x100')#設(shè)定root窗口的大小label=Label(root,text='這是個標(biāo)簽')#創(chuàng)建一個標(biāo)簽,第一個參數(shù)是當(dāng)前對象加入的容器,#默認(rèn)是主窗口label.pack()#標(biāo)簽用packer布局方式放入容器rootroot.mainloop()#等待響應(yīng)用戶事件要用tkinter庫實現(xiàn)圖形界面,必須先導(dǎo)入tkinter模塊,見第1行。主窗口只能有一個,主窗口是其他所有組件的最底層容器,容器是可以嵌套的。程序可以不創(chuàng)建主窗口,系統(tǒng)會默認(rèn)創(chuàng)建。用Tk()函數(shù)創(chuàng)建主窗口,見代碼第2行。用組件可以創(chuàng)建組件對象,見代碼第4行,創(chuàng)建一個Labe組件的label,創(chuàng)建Label對象時,輸入的第一個參數(shù)是指當(dāng)前組件對象的容器。,label的容器是root,如果不指定容器,默認(rèn)容器就是主窗口。其他參數(shù)用于設(shè)定對象的各個屬性。比如,text='這是個標(biāo)簽'是設(shè)定當(dāng)前標(biāo)簽對象的文本內(nèi)容是“這是個標(biāo)簽”。第6行,指定組件放入容器的布局方式,此行語句是指定packer布局方式。packer方式,在默認(rèn)情況下,當(dāng)前組件對象放入上個對象的下方中間位置。代碼第7行,窗口開始循環(huán)等待用戶對圖形界面觸發(fā)事件,然后對事件進行響應(yīng)。也可以用config函數(shù)設(shè)置或者修改組件對象的屬性,如圖。2.tkinter圖形界面布局tkinter常用組件布局方式有packer布局、grid布局、place布局,決定了組件對象以怎樣的布局方式出現(xiàn)在容器中。創(chuàng)建組件后,如果沒有指定布局方式,組件是不會顯示在容器中的。一個容器只能使用一種布局方式。1.pack幾何布局管理器代碼練習(xí)1:fromtkinterimport*label1=Label(text='標(biāo)簽1')label1.config(fg='red',bg='black')label2=Label(text='標(biāo)簽2')label2.config(fg='yellow',bg='blue')label3=Label(text='標(biāo)簽3')label3.config(fg='white',bg='green')label1.pack()label2.pack(side=BOTTOM)label3.pack(side=RIGHT)mainloop()代碼練習(xí)2:fromtkinterimport*label1=Label(text='標(biāo)簽1')label1.config(fg='red',bg='yellow')label2=Label(text='標(biāo)簽2')label2.config(fg='yellow',bg='blue')label3=Label(text='標(biāo)簽3')label3.config(fg='white',bg='green')label1.pack(anchor=NE)label2.pack(anchor=N)label3.pack(anchor=SW)mainloop()2.grid幾何布局管理器代碼練習(xí)3:fromtkinterimport*label1=Label(text='標(biāo)簽1')label1.config(fg='red',bg='yellow')label2=Label(text='標(biāo)簽2')label2.config(fg='yellow',bg='blue')label3=Label(text='標(biāo)簽3')label3.config(fg='white',bg='green')label1.grid(row=0,column=3)label2.grid(row=1,column=2)label3.grid(row=1,column=1)mainloop()代碼練習(xí)4:fromtkinterimport*label1=Label(text='標(biāo)簽1')label1.config(fg='red',bg='yellow')label2=Label(text='標(biāo)簽2')label2.config(fg='yellow',bg='blue')label3=Label(text='標(biāo)簽3')label3.config(fg='white',bg='green')label1.grid(row=0,column=3)label2.grid(row=4,column=2)label3.grid(row=4,column=1)mainloop()3.place幾何布局管理器place幾何布局管理允許指定組件的大小與位置。place的優(yōu)點是可以精確控制組件的位置,不足之處是改變窗口大小時,子組件不能隨之靈活改變大小。代碼練習(xí)5:fromtkinterimport*label1=Label(text='標(biāo)簽1')label1.config(fg='red',bg='yellow')label2=Label(text='標(biāo)簽2')label2.config(fg='yellow',bg='blue')label3=Label(text='標(biāo)簽3')label3.config(fg='white',bg='green')label1.place(x=0,y=0)label2.place(x=50,y=50)label3.place(relx=0.5,rely=0.2)mainloop()代碼練習(xí)6:fromtkinterimport*defshowmsg():label1.config(text='我被單擊了!')label1=Label(text='這是個標(biāo)簽')label1.pack()#command參數(shù)指定單擊按鈕要執(zhí)行的函數(shù)名btn=Button(text='按鈕',command=showmsg)btn.pack()mainloop()3.完成主界面代碼fromtkinterimport*fromtkinter.messageboximportaskokcancelroot=Tk()systitle='班級信息管理系統(tǒng)'#系統(tǒng)標(biāo)題defmain():root.geometry('600x400')#設(shè)置窗口初始大小root.title(systitle)#設(shè)置系統(tǒng)標(biāo)題#創(chuàng)建系統(tǒng)菜單menubar=Menu(root)#創(chuàng)建Menu對象menubar,將作為root窗口中的菜單root.config(menu=menubar)#將menubar菜單作為root窗口的頂層菜單欄#定義menuStudent,作為menubar菜單的子菜單menuStudent=Menu(menubar,tearoff=0)#菜單menuStudent的父菜單是menubarmenuStudent.add_command(label='添加新學(xué)生',font=('宋體',10),command=addStudent)menuStudent.add_command(label='顯示全部學(xué)生信息',font=('宋體',10),command=showAllStudent)menuStudent.add_command(label='查找/修改/刪除學(xué)生信息',font=('宋體',10),command=checkUpdateStudent)menuStudent.add_separator()menuStudent.add_command(label='退出',font=('宋體',10),command=goexit)#菜單'學(xué)生管理'添加為menubar的子菜單menubar.add_cascade(label='學(xué)生管理',font=('宋體',10),menu=menuStudent)menuHelp=Menu(menubar,tearoff=0)#menuHelp將作為menubar菜單的子菜單menuHelp.add_command(label='查看日志',font=('宋體',10),command=showlog)menuHelp.add_command(label='關(guān)于...',font=('宋體',10),command=showabout)#菜單menuHelp添加為menubar的子菜單menubar.add_cascade(label='其他',font=('宋體',10),menu=menuHelp)root.mainloop()defshowAllStudent():passdefcheckUpdateStudent():passdefaddStudent():passdefgoexit():ifaskokcancel('學(xué)生信息管理系統(tǒng)','確定退出系統(tǒng)?'):exit(0)defshowlog():passdefshowabout():passif__name__=='__main__':main()圖界面圖片4.Python訪問SQLite數(shù)據(jù)庫SQLite是Python自帶的關(guān)系數(shù)據(jù)庫,不需要安裝獨立的服務(wù)器。其他的數(shù)據(jù)庫則需要自行下載并安裝,Python通過第三方擴展口來訪問。(1)連接和創(chuàng)建SQLite數(shù)據(jù)庫訪問SQLite數(shù)據(jù)庫時,需要先導(dǎo)入sqlite3模塊,然后調(diào)用connect()函數(shù)建立數(shù)據(jù)庫連接,獲得數(shù)據(jù)庫連接對象。例如:importsqlite3cn=sqlite3.connect(student.db')connect()函數(shù)的參數(shù)為SQLite數(shù)據(jù)庫文件名。如果指定的數(shù)據(jù)庫不存在,則用該名稱創(chuàng)建一個新的數(shù)據(jù)庫。如果使用“:memory:”表示文件名,Python會創(chuàng)建一個內(nèi)存數(shù)據(jù)庫。內(nèi)存數(shù)據(jù)庫中的所有數(shù)據(jù)均保存在內(nèi)存中,關(guān)閉連接對象的時候,所有數(shù)據(jù)自動刪除。例如:importsqlite3cn=sqlite3.connect(“:memory:”)通過上面內(nèi)容的學(xué)習(xí),現(xiàn)在經(jīng)過拓展將新增學(xué)生這個功能進行完成。fromtkinterimport*fromtkinter.messageboximportaskokcancel,showinfofromsqlite3import*root=Tk()systitle='班級信息管理系統(tǒng)'#系統(tǒng)標(biāo)題dbfile='student.db'#v2cn=connect(dbfile)#v2連接數(shù)據(jù)庫,連接對象cnoperateFrame=Frame()#功能窗口operateFrame.pack()defmain():root.geometry('600x400')#設(shè)置窗口初始大小root.title(systitle)#設(shè)置系統(tǒng)標(biāo)題#創(chuàng)建系統(tǒng)菜單menubar=Menu(root)#創(chuàng)建Menu對象menubar,將作為root窗口中的菜單root.config(menu=menubar)#將menubar菜單作為root窗口的頂層菜單欄#menuStudent將作為menubar菜單的子菜單menuStudent=Menu(menubar,tearoff=0)menuStudent.add_command(label='添加新學(xué)生',font=('宋體',10),command=addStudent)menuStudent.add_command(label='顯示全部學(xué)生信息',font=('宋體',10),command=showAllStudent)menuStudent.add_command(label='查找/修改/刪除學(xué)生信息',font=('宋體',10),command=checkUpdateStudent)menuStudent.add_separator()menuStudent.add_command(label='退出',font=('宋體',10),command=goexit)#菜單file添加為menubar的子菜單menubar.add_cascade(label='學(xué)生管理',font=('宋體',10),menu=menuStudent)#menuSubject將作為menubar菜單的子菜單menuSubject=Menu(menubar,tearoff=0)menuSubject.add_command(label='添加新科目',font=('宋體',10),command=addSubject)menuSubject.add_command(label='顯示全部科目',font=('宋體',10),command=showAllSubject)menuSubject.add_command(label='查找/修改/刪除科目',font=('宋體',10),command=checkUpdateSubject)menubar.add_cascade(label='科目管理',font=('宋體',10),menu=menuSubject)#menuSubject將作為menubar菜單的子菜單menuScore=Menu(menubar,tearoff=0)menuScore.add_command(label='錄入成績',font=('宋體',10),command=inputScore)#下級菜單“查詢成績”--子菜單1-按照科目查詢-子菜單2-按照學(xué)號查詢menuSearch=Menu(menubar,tearoff=0)menuSearch.add_command(label='按照科目查詢',font=('宋體',10),command=searchScoreBySid)menuSearch.add_command(label='按照學(xué)號查詢',font=('宋體',10),command=searchScoreByUid)menuScore.add_cascade(label='查詢成績',font=('宋體',10),menu=menuSearch)#完成“查詢成績”下級菜單menuScore.add_command(label='成績輸出為excel表',font=('宋體',10),command=outputExcel)menubar.add_cascade(label='成績管理',font=('宋體',10),menu=menuScore)menuHelp=Menu(menubar,tearoff=0)#help將作為menubar菜單的子菜單menuHelp.add_command(label='查看日志',font=('宋體',10),command=showlog)menuHelp.add_command(label='關(guān)于...',font=('宋體',10),command=showabout)#菜單help添加為menubar的子菜單menubar.add_cascade(label='其他',font=('宋體',10),menu=menuHelp)root.mainloop()defshowAllStudent():passdefcheckUpdateStudent():passdefaddStudent():forwidgetinoperateFrame.winfo_children():#清空窗口中原有的所有內(nèi)容widget.destroy()f1=Frame(operateFrame)f1.pack()studentIdVar=StringVar()studentNameVar=StringVar()ageVar=StringVar()telVar=StringVar()lStudentId=Label(f1,text='學(xué)號:')lStudentName=Label(f1,text='姓名:')lAge=Label(f1,text='年齡:')lTel=Label(f1,text='電話:')tStudentId=Entry(f1,textvariable=studentIdVar)tStudentName=Entry(f1,textvariable=studentNameVar)tAge=Entry(f1,textvariable=ageVar)tTel=Entry(f1,textvariable=telVar)lStudentId.grid(row=1,column=1)lStudentName.grid(row=2,column=1)lAge.grid(row=3,column=1)lTel.grid(row=4,column=1)tStudentId.grid(row=1,column=2)tStudentName.grid(row=2,column=2)tAge.grid(row=3,column=2)tTel.grid(row=4,column=2)f2=Frame(operateFrame)f2.pack(pady=20)bReset=Button(f2,text='重置')bSave=Button(f2,text='保存')bReset.grid(row=1,column=1)bSave.grid(row=1,column=2)defreset():studentIdVar.set('')studentNameVar.set('')ageVar.set('')telVar.set('')bReset.config(command=reset)defsave(event):try:id=studentIdVar.get()ifnotid.isdigit():raiseException('學(xué)號必須為數(shù)字!')eliflen(id)!=4:raiseException('學(xué)號必須是4位!')name=studentNameVar.get()age=ageVar.get()ifnotage.isdigit():raiseException('年齡錯誤!')else:age=int(age)ifage<15orage>50:raiseException('年齡必須大于15小于50!')tel=telVar.get()ifnottel.isdigit():raiseException('電話錯誤!')eliflen(tel)!=4:raiseException('電話必須4位!')#向數(shù)據(jù)庫發(fā)送插入指令cn.execute('INSERTINTOstudentVALUES(?,?,?,?)',(id,name,age,tel))mit()showinfo(systitle,'成功添加新學(xué)生!')reset()tStudentId.focus()#測試:向數(shù)據(jù)庫發(fā)一個查詢指令#獲得了一個列表,列表中每個單元是一個學(xué)生,每個學(xué)生是一個元組#stulist=cn.execute('SELECT*FROMstudent').fetchall()#print(stulist)exceptExceptionasex:showinfo(systitle,ex)bSave.config(command=save)tTel.bind('<Return>',save)defaddSubject():passdefshowAllSubject():passdefcheckUpdateSubject():passdefinputScore():passdefsearchScoreBySid():passdefsearchScoreByUid():passdefoutputExcel():passdefgoexit():ifaskokcancel('學(xué)生信息管理系統(tǒng)','確定退出系統(tǒng)?'):exit(0)defshowlog():passdefshowabout():passif__name__=='__main__':main()6顯示所有學(xué)生defshowAllStudent():#v3forwidgetinoperateFrame.winfo_children():#清空窗口中原有的所有內(nèi)容widget.destroy()operateFrame.columnconfigure(1,minsize=50)operateFrame.columnconfigure(2,minsize=100)operateFrame.columnconfigure(3,minsize=50)operateFrame.columnconfigure(4,minsize=100)Label(operateFrame,text='學(xué)號',font=('宋體',10,'bold')).grid(row=0,column=1)Label(operateFrame,text='姓名',font=('宋體',10,'bold')).grid(row=0,column=2)Label(operateFrame,text='年齡',font=('宋體',10,'bold')).grid(row=0,column=3)Label(operateFrame,text='電話',font=('宋體',10,'bold')).grid(row=0,column=4)stulist=cn.execute('select*fromstudent').fetchall()rownum=1forstuinstulist:colnum=1forinfoinstu:Label(operateFrame,text=str(info),font=('宋體',10)).grid(row=rownum,column=colnum)colnum+=1rownum+=1查找刪除修改學(xué)生defcheckUpdateStudent():#v4forwidgetinoperateFrame.winfo_children():#清空窗口中原有的所有內(nèi)容widget.destroy()f1=LabelFrame(operateFrame,text='查找學(xué)生:')f1.pack()studentIdToSearchVar=StringVar()Label(f1,text='請輸入要查找的學(xué)生學(xué)號:').grid(row=1,column=1)tStudentIdToSearch=Entry(f1,textvariable=studentIdToSearchVar)tStudentIdToSearch.grid(row=1,column=2)bSearch=Button(f1,text='查詢')bSearch.grid(row=1,column=3)f2=LabelFrame(operateFrame,text='刪除與修改學(xué)生:')f2.pack(pady=30)fDelete=Frame(f2)fDelete.pack()bDelete=Button(fDelete,text='刪除學(xué)生',state=DISABLED)bDelete.pack()fUpdate=Frame(f2)fUpdate.pack()studentIdVar=StringVar()studentNameVar=StringVar()ageVar=StringVar()telVar=StringVar()Label(fUpdate,text='學(xué)號:').grid(row=1,column=1)Label(fUpdate,text='姓名:').grid(row=2,column=1)Label(fUpdate,text='年齡:').grid(row=3,column=1)Label(fUpdate,text='電話:').grid(row=4,column=1)Entry(fUpdate,textvariable=studentIdVar,state=DISABLED).grid(row=1,column=2)Entry(fUpdate,textvariable=studentNameVar).grid(row=2,column=2)Entry(fUpdate,textvariable=ageVar).grid(row=3,column=2)Entry(fUpdate,textvariable=telVar).grid(row=4,column=2)bSave=Button(fUpdate,text='保存修改',state=DISABLED)bSave.grid(row=4,column=3)defsearch(event=None):studentIdVar.set('')studentNameVar.set('')ageVar.set('')telVar.set('')studentIdToSearch=studentIdToSearchVar.get()stu=cn.execute('SELECTsid,sname,age,telFROMstudentWHEREsid=?',(studentIdToSearch,)).fetchone()print(stu)ifstu==None:showinfo(systitle,'該學(xué)生不存在')bSave.config(state=DISABLED)bDelete.config(state=DISABLED)else:studentIdVar.set(stu[0])studentNameVar.set(stu[1])ageVar.set(stu[2])telVar.set(stu[3])bDelete.config(state=NORMAL)bSave.config(state=NORMAL)bSearch.config(command=search)tStudentIdToSearch.bind("<Return>",search)defdelete():cn.execute('DELETEFROMstudentWHEREsid=?',(studentIdVar.get(),))mit()showinfo(systitle,'成功刪除!')studentIdVar.set('')studentNameVar.set('')ageVar.set('')telVar.set('')bDelete.config(command=delete)defsave():cn.execute('UPDATEstudentSETsname=?,age=?,tel=?WHEREsid=?',(studentNameVar.get(),ageVar.get(),telVar.get(),studentIdVar.get()))mit()showinfo(systitle,'成功修改!')bSave.config(command=save)成績錄入#v6成績管理definputScore():forwidgetinoperateFrame.winfo_children():#清空窗口中原有的所有內(nèi)容widget.destroy()f1=Frame(operateFrame)f1.pack()Label(f1,text='科目名稱:').grid(row=1,column=1)subjectNameVar=StringVar()comboxSubjectName=Combobox(f1,textvariable=subjectNameVar)comboxSubjectName.grid(row=1,column=2)bSave=Button(f1,text='保存成績')bSave.grid(row=1,column=3)subjectList=cn.execute('SELECTcid,cnameFROMcourse').fetchall()subjectNameList=[]forsubinsubjectList:subjectNameList.append(sub[1])comboxSubjectName["values"]=subjectNameListcomboxSubjectName.current(0)f2=Frame(operateFrame)f2.pack()Label(f2,text='學(xué)號',width=10).grid(row=1,column=1)Label(f2,text='姓名',width=10).grid(row=1,column=2)Label(f2,text='成績',width=10).grid(row=1,column=3)f3=Frame(operateFrame)#輸入成績的內(nèi)容窗口f3.pack()defgo(*args):#處理事件,*args表示可變參數(shù)forwidgetinf3.winfo_children():#清空輸入成績的內(nèi)容窗口widget.destroy()scoreVarList=[]studentList=cn.execute('SELECTsid,snameFROMstudentORDERBYsid').fetchall()r=2forstuinstudentList:Label(f3,text=stu[0],width=10).grid(row=r,column=1)Label(f3,text=stu[1],width=10).grid(row=r,column=2)#當(dāng)前科目,每個學(xué)生對應(yīng)一個輸入成績的文本框#每個成績文本框?qū)?yīng)的控制變量,依次構(gòu)成列表scoreVarListscoreVar=StringVar()scoreVarList.append(scoreVar)Entry(f3,textvariable=scoreVar,width=10).grid(row=r,column=3)r+=1#取到當(dāng)前科目名稱對應(yīng)的編號subjectNameChosed=subjectNameVar.get()forsubinsubjectList:ifsub[1]==subjectNameChosed:subjectIdChosed=sub[0]#把當(dāng)前科目之前已經(jīng)錄入的成績顯示出來scoreExistList=cn.execute('SELECTsid,gradeFROMscoreWHEREcid=?',(subjectIdChosed,)).fetchall()forstu,scoreVarinzip(studentList,scoreVarList):forsinscoreExistList:ifstu[0]==s[0]:scoreVar.set(s[1])defsave():#保存成績:學(xué)號、科目編號、成績#先清空當(dāng)前科目的所有成績cn.execute('DELETEFROMscoreWHEREcid=?',(subjectIdChosed,))mit()forstu,gradeinzip(studentList,scoreVarList):s=grade.get().strip()ifs.isdigit():s=int(s)ifs>=0ands<=100:cn.execute('INSERTINTOscoreVALUES(?,?,?)',(stu[0],subjectIdChosed,s))else:showinfo(systitle,'成績必須在0-100之間')elifs!='':showinfo(systitle,'成績不合理!')mit()#測試#scoreList=cn.execute('SELECT*FROMscore').fetchall()#print(scoreList)bSave.config(command=save)comboxSubjectName.bind("<<ComboboxSelected>>",go)#綁定事件成績查詢#v7成績查詢defsearchScoreBySid():#按科目編號查詢forwidgetinoperateFrame.winfo_children():#清空窗口中原有的所有內(nèi)容widget.destroy()f1=Frame(operateFrame)f1.pack()subjectNameToSearchVar=StringVar()Label(f1,text="科目名稱").grid(row=1,column=1)comboxSubjectNameToSearch=Combobox(f1,textvariable=subjectNameToSearchVar)comboxSubjectNameToSearch.grid(row=1,column=2)subjectList=cn.execute('SELECTcid,cnameFROMcourse').fetchall()subjectNameList=[]forsubinsubjectList:subjectNameList.append(sub[1])comboxSubjectNameToSearch['values']=subjectNameListf2=Frame(operateFrame)f2.pack()Label(f2,text='學(xué)號',width=20).grid(row=1,column=1)Label(f2,text='姓名',width=20).grid(row=1,column=2)Label(f2,text='科目名稱',width=20).grid(row=1,column=3)Label(f2,text='成績',width=20).grid(row=1,column=4)f3=Frame(operateFrame)f3.pack()defsearch(*args):forwidgetinf3.winfo_children():#清空f3窗口中原有的所有內(nèi)容widget.destroy()subjectNameToSearch=subjectNameToSearchVar.get()forsubinsubjectList:ifsub[1]==subjectNameToSearch:subjectIdToSearch=sub[0]sc
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 ISO/TS 20428:2024 EN Genomics Informatics - Data elements and their metadata for describing structured clinical genomic sequence information in electronic health records
- 【正版授權(quán)】 ISO 6900:2025 EN Dried red jujubes - Specification and test methods
- 2025年度大型企事業(yè)單位公務(wù)車輛租賃服務(wù)協(xié)議合同范本
- 2025年變配電保護自動化項目合作計劃書
- 離職管理與退出面談流程計劃
- 秋季信息化教學(xué)推進計劃
- 2025年酸堿平衡調(diào)節(jié)藥合作協(xié)議書
- 智研咨詢發(fā)布-2025年中國智慧環(huán)保行業(yè)產(chǎn)業(yè)鏈全景分析及發(fā)展趨勢預(yù)測報告
- 2025年特異性植物源農(nóng)藥項目合作計劃書
- 2025年醫(yī)用氧化亞氮系統(tǒng)合作協(xié)議書
- 電力電子技術(shù)全套課件
- 配電箱(剩余電流動作斷路器)檢測報告
- 編外人員錄用審批表
- 倪海廈《天紀(jì)》講義
- DB32T 4004-2021 水質(zhì) 17種全氟化合物的測定 高效液相色譜串聯(lián)質(zhì)譜法
- 建設(shè)年飼養(yǎng)240萬只蛋雛雞培育基地項目可行性研究報告
- 大連理工畫法幾何電子教案2003第八章
- 中國數(shù)學(xué)發(fā)展歷史(課堂PPT)
- 黃金太陽漆黑的黎明金手指
- 車間、設(shè)備改造項目建議書范文
- 化學(xué)成份及性能對照表新
評論
0/150
提交評論