<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
本文範例為大家分享了python tkinter實現學生資訊管理系統的具體程式碼,供大家參考,具體內容如下
初學python,程式碼寫的比較繁雜,系統功能還有完善的空間
系統使用了mysql資料庫,資料庫:sch,使用者名稱:root ,密碼:123456,建立表的語句寫在程式碼裡面了
import tkinter import tkinter.messagebox import re import pymysql from tkinter import scrolledtext import os from tkinter import * def window_info(main): w = main.winfo_screenwidth() h = main.winfo_screenheight() x = (w / 2) - 200 y = (h / 2) - 200 return (x, y) def conn(): con = pymysql.connect("localhost", "root", "root", "sch") return con def cur(connection): cur = connection.cursor() return cur def exitsys(): root.destroy() def teacherlogin(): #=============================================================================== def managerindex(): def addstudent(): def addone(): connection = conn() cursor = cur(connection) try: cursor.execute('insert into student values(%s,%s,%s,%s,%s)', (addnameentry.get(), addageentry.get(), addnoentry.get(), addclassentry.get(),'未註冊')) connection.commit() except: if addsuccessentry.get() != '': addsuccessentry.delete('0', 'end') addsuccessentry.insert('0', '新增失敗!') else: addsuccessentry.insert('0', '新增失敗!') connection.rollback() connection.close() cursor.close if addsuccessentry.get() != '': addsuccessentry.delete('0', 'end') addsuccessentry.insert('0', '新增成功!') else: addsuccessentry.insert('0', '新增成功!') def addcancel(): addnameentry.delete('0', 'end') addageentry.delete('0', 'end') addnoentry.delete('0', 'end') addclassentry.delete('0', 'end') addsuccessentry.delete('0', 'end') def exit(): add.destroy() add = Toplevel() add.title('新增學生資訊') x, y = window_info(add) add.geometry("415x295+%d+%d" % (x, y)) add['bg'] = 'dodgerblue' labelname = tkinter.Label(add, text='新增學生', width=80, bg='dodgerblue') labelname.place(x=140, y=50, width=150, height=20) labelname = tkinter.Label(add, text='學生名:', width=80) labelname.place(x=140, y=80, width=60, height=20) addnameentry = tkinter.Entry(add, width=200) addnameentry.place(x=195, y=80, width=80, height=20) labelage = tkinter.Label(add, text='年 齡:', width=80) labelage.place(x=140, y=110, width=60, height=20) addageentry = tkinter.Entry(add, width=200) addageentry.place(x=195, y=110, width=80, height=20) labelno = tkinter.Label(add, text='學 號:', width=80) labelno.place(x=140, y=140, width=60, height=20) addnoentry = tkinter.Entry(add, width=200) addnoentry.place(x=195, y=140, width=80, height=20) labelclass = tkinter.Label(add, text='班 級:', width=80) labelclass.place(x=140, y=170, width=60, height=20) addclassentry = tkinter.Entry(add, width=200) addclassentry.place(x=195, y=170, width=80, height=20) addsuccessentry = tkinter.Entry(add, width=200, state='normal') addsuccessentry.place(x=140, y=200, width=135, height=20) buttonadd = tkinter.Button(add, text="新增", command=addone) buttonadd.place(x=140, y=230, width=50, height=20) buttoncancel = tkinter.Button(add, text="重置", command=addcancel) buttoncancel.place(x=220, y=230, width=50, height=20) add.mainloop() return add # =================================================================================== def findonestudent(): def search(): if textsearch.get('1.0', 'end') != '': textsearch.delete('1.0', 'end') else: connection = conn() cursor = cur(connection) try: cursor.execute('select * from student where sno=%s', (entrysearchone.get())) data = list(cursor.fetchone()) textsearch.insert('insert', "學生姓名:" + data[0] + "n" + "年齡:" + data[1] + "n" + "學號" + data[2] + "n" + "班級:" + data[3] + "nn") connection.commit() except: connection.rollback() connection.close() cursor.close connection = conn() cursor = cur(connection) try: cursor.execute('select * from student where sno=%s', (entrysearchone.get())) data = list(cursor.fetchone()) textsearch.insert('insert', "學生姓名:" + data[0] + "n" + "年齡:" + data[1] + "n" + "學號" + data[2] + "n" + "班級:" + data[3] + "nn") connection.commit() except: connection.rollback() connection.close() cursor.close def searchonecancel(): textsearch.delete('1.0', 'end') def searchnocancel(): entrysearchone.delete('0', 'end') def exit(): findone.destroy() findone = Toplevel() findone.title('查詢學生資訊') x, y = window_info(findone) findone.geometry("415x295+%d+%d" % (x, y)) findone['bg'] = 'dodgerblue' labelname = tkinter.Label(findone, text='請輸入要查詢學生的學號:', width=80, bg='dodgerblue') labelname.place(x=140, y=50, width=140, height=20) entrysearchone = tkinter.Entry(findone, width=200) entrysearchone.place(x=140, y=80, width=150, height=20) buttonsearch = tkinter.Button(findone, text="查詢", command=search) buttonsearch.place(x=140, y=110, width=50, height=20) buttonsearch = tkinter.Button(findone, text="重置", command=searchnocancel) buttonsearch.place(x=240, y=110, width=50, height=20) textsearch = tkinter.scrolledtext.ScrolledText(findone, width=18, height=6) textsearch.place(x=140, y=140) buttoncancel = tkinter.Button(findone, text="清空", command=searchonecancel) buttoncancel.place(x=190, y=230, width=50, height=20) findone.mainloop() # ================================================================================== def deletestudent(): def deleteone(): if deleteoneentry.get() == '': tkinter.messagebox.showerror('error', message="請輸入學號!") else: if textdelete.get('1.0', 'end') != '': textdelete.delete('1.0', 'end') else: connection = conn() cursor = cur(connection) try: cursor.execute('delete from student where sno=%s', (deleteoneentry.get())) connection.commit() cursor.execute('select * from student') data = list(cursor.fetchall()) textdelete.insert('insert', "姓名:tt年齡:tt學號:tt班級:") textdelete.insert('insert', "n") for i in data: print(i) textdelete.insert('insert', 'tt'.join(i)) textdelete.insert('insert', "n") except: connection.rollback() connection.close() cursor.close connection = conn() cursor = cur(connection) try: cursor.execute('delete from student where sno=%s', (deleteoneentry.get())) connection.commit() cursor.execute('select * from student') data = list(cursor.fetchall()) textdelete.insert('insert', "姓名:tt年齡:tt學號:tt班級:") textdelete.insert('insert', "n") for i in data: print(i) textdelete.insert('insert', 'tt'.join(i)) textdelete.insert('insert', "n") except: connection.rollback() connection.close() cursor.close def exit(): deleteone.destroy() def deleteonecancel(): deleteoneentry.delete('0', 'end') delete = Toplevel() delete.title('刪除學生資訊') x, y = window_info(delete) delete.geometry("415x295+%d+%d" % (x, y)) delete['bg'] = 'dodgerblue' labelname = tkinter.Label(delete, text='請輸入要刪除學生的學號:', bg='dodgerblue') labelname.place(x=5, y=20, width=140, height=20) deleteoneentry = tkinter.Entry(delete, width=200) deleteoneentry.place(x=5, y=50, width=150, height=20) buttondelete = tkinter.Button(delete, text="刪除", command=deleteone) buttondelete.place(x=5, y=80, width=50, height=20) buttondelete = tkinter.Button(delete, text="重置", command=deleteonecancel) buttondelete.place(x=105, y=80, width=50, height=20) textdelete = tkinter.scrolledtext.ScrolledText(delete, width=54, height=9) textdelete.place(x=5, y=110) delete.mainloop() # ======================================================================================= def findallstudent(): def show(): if textshow.get('1.0', 'end') != '': textshow.delete('1.0', 'end') else: connection = conn() cursor = cur(connection) try: cursor.execute('select * from student') data = list(cursor.fetchall()) textshow.insert('insert', "姓名:tt年齡:tt學號:tt班級:tt登入密碼:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'tt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close connection = conn() cursor = cur(connection) try: cursor.execute('select * from student') data = list(cursor.fetchall()) textshow.insert('insert', "姓名:tt年齡:tt學號:tt班級:tt登入密碼:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'tt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close def searchallcancel(): textshow.delete('1.0', 'end') def exit(): findall.destroy() findall = Toplevel() findall.title('查詢所有學生資訊') x, y = window_info(findall) findall.geometry("520x295+%d+%d" % (x, y)) findall['bg'] = 'dodgerblue' labelname = tkinter.Label(findall, text='查詢所有學生資訊?', bg='dodgerblue') labelname.place(x=5, y=20, width=100, height=20) buttonshow = tkinter.Button(findall, text="確定", command=show) buttonshow.place(x=5, y=50, width=50, height=20) textshow = tkinter.scrolledtext.ScrolledText(findall, width=75, height=9) textshow.place(x=5, y=80) buttoncancel = tkinter.Button(findall, text="清空", command=searchallcancel) buttoncancel.place(x=5, y=210, width=50, height=20) findall.mainloop() # ======================================================================================= def modifystudent(): def modifyfindone(): connection = conn() cursor = cur(connection) try: cursor.execute('select * from student where sno=%s', (modifyoneentry.get())) connection.commit() except: connection.rollback() connection.close() cursor.close data = list(cursor.fetchall()) if data == []: tkinter.messagebox.showerror(message="沒有查詢到該學生的資訊!") else: modifynameentry.insert('0', data[0][0]) modifyageentry.insert('0', data[0][1]) modifynoentry.insert('0', data[0][2]) modifyclassentry.insert('0', data[0][3]) def submit(): print(modifynameentry.get()) print(modifyoneentry.get()) connection = conn() cursor = cur(connection) sqlname = "update student set sname = %s where sno = %s" cursor.execute(sqlname, (modifynameentry.get(), modifyoneentry.get())) sqlage = "update student set sage = %s where sno = %s" cursor.execute(sqlage, (modifyageentry.get(), modifyoneentry.get())) sqlno = "update student set sno = %s where sno = %s" cursor.execute(sqlno, (modifynoentry.get(), modifyoneentry.get())) sqlclass = "update student set sclass = %s where sno = %s" cursor.execute(sqlclass, (modifyclassentry.get(), modifyoneentry.get())) connection.commit() if modifysuccessentry.get() != '': modifysuccessentry.delete('0', 'end') modifysuccessentry.insert('0', '修改成功!') else: modifysuccessentry.insert('0', '修改成功!') modify = Toplevel() modify.title('修改學生資訊') x, y = window_info(modify) modify.geometry("415x295+%d+%d" % (x, y)) modify['bg'] = 'dodgerblue' labelname = tkinter.Label(modify, text='請輸入要修改學生的學號:', bg='dodgerblue') labelname.place(x=5, y=20, width=140, height=20) buttonshow = tkinter.Button(modify, text="確定", command=modifyfindone) buttonshow.place(x=155, y=50, width=50, height=20) modifyoneentry = tkinter.Entry(modify, width=200) modifyoneentry.place(x=5, y=50, width=150, height=20) labelname = tkinter.Label(modify, text='該學生資訊如下', bg='dodgerblue') labelname.place(x=5, y=70, width=85, height=20) labelname = tkinter.Label(modify, text='姓名:',bg='dodgerblue') labelname.place(x=5, y=100, width=30, height=20) modifynameentry = tkinter.Entry(modify, width=200) modifynameentry.place(x=5, y=120, width=150, height=20) labelname = tkinter.Label(modify, text='年齡:',bg='dodgerblue') labelname.place(x=200, y=100, width=30, height=20) modifyageentry = tkinter.Entry(modify, width=200) modifyageentry.place(x=200, y=120, width=150, height=20) labelname = tkinter.Label(modify, text='學號:',bg='dodgerblue') labelname.place(x=5, y=150, width=30, height=20) modifynoentry = tkinter.Entry(modify, width=200) modifynoentry.place(x=5, y=170, width=150, height=20) labelname = tkinter.Label(modify, text='班級:',bg='dodgerblue') labelname.place(x=200, y=150, width=30, height=20) modifyclassentry = tkinter.Entry(modify, width=200) modifyclassentry.place(x=200, y=170, width=150, height=20) modifysuccessentry = tkinter.Entry(modify, width=200) modifysuccessentry.place(x=5, y=200, width=150, height=20) buttonshow = tkinter.Button(modify, text="提 交", command=submit) buttonshow.place(x=5, y=230, width=50, height=20) modify.mainloop() # ================================================================================== def findselectcourseinfor(): def show(): print('swj') if textshow.get('1.0', 'end') != '': textshow.delete('1.0', 'end') else: connection = conn() cursor = cur(connection) try: cursor.execute('select sno,sname,sclass,cno,cname from student,course where student.sno=sc.sno and course.cno=sc.cno') data = list(cursor.fetchall()) textshow.insert('insert', "學號:tt姓名:tt班級:tt課程編號:tt課程名:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'tt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close connection = conn() cursor = cur(connection) try: cursor.execute('select sc.sno,sname,sclass,sc.cno,course.cname from student,course,sc where student.sno=sc.sno and course.cno=sc.cno') data = list(cursor.fetchall()) textshow.insert('insert', "學號:tt姓名:tt班級:tt課程編號:tt課程名:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'tt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close def searchallcancel(): textshow.delete('1.0', 'end') findall = Toplevel() findall.title('查詢學生選課資訊') x, y = window_info(findall) findall.geometry("520x295+%d+%d" % (x, y)) findall['bg'] = 'dodgerblue' labelname = tkinter.Label(findall, text='查詢學生選課資訊?', bg='dodgerblue') labelname.place(x=5, y=20, width=100, height=20) buttonshow = tkinter.Button(findall, text="確定", command=show) buttonshow.place(x=5, y=50, width=50, height=20) textshow = tkinter.scrolledtext.ScrolledText(findall, width=105, height=9) textshow.place(x=5, y=80) buttoncancel = tkinter.Button(findall, text="清空", command=searchallcancel) buttoncancel.place(x=5, y=210, width=50, height=20) findall.mainloop() #=================================================================================== def addcourse(): def addonecourse(): print(addcnoentry.get()) connection = conn() cursor = cur(connection) try: cursor.execute('insert into course values(%s,%s,%s)', (addcnoentry.get(), addcnameentry.get(), addtnoentry.get())) connection.commit() except: if addsuccessentry.get() != '': addsuccessentry.delete('0', 'end') addsuccessentry.insert('0', '新增失敗!') else: addsuccessentry.insert('0', '新增失敗!') connection.rollback() connection.close() cursor.close if addsuccessentry.get() != '': addsuccessentry.delete('0', 'end') addsuccessentry.insert('0', '新增成功!') else: addsuccessentry.insert('0', '新增成功!') def addcancel(): addcnoentry.delete('0', 'end') addcnameentry.delete('0', 'end') addtnoentry.delete('0', 'end') addsuccessentry.delete('0', 'end') addcourse = Toplevel() addcourse.title('新增學生資訊') x, y = window_info(addcourse) addcourse.geometry("415x295+%d+%d" % (x, y)) addcourse['bg'] = 'dodgerblue' labelname = tkinter.Label(addcourse, text='新增學生', width=80, bg='dodgerblue') labelname.place(x=140, y=50, width=150, height=20) labelname = tkinter.Label(addcourse, text='課程號:', width=80) labelname.place(x=140, y=80, width=60, height=20) addcnoentry = tkinter.Entry(addcourse, width=200) addcnoentry.place(x=195, y=80, width=80, height=20) labelage = tkinter.Label(addcourse, text='課程名:', width=80) labelage.place(x=140, y=110, width=60, height=20) addcnameentry = tkinter.Entry(addcourse, width=200) addcnameentry.place(x=195, y=110, width=80, height=20) labelno = tkinter.Label(addcourse, text='教師編號:', width=80) labelno.place(x=140, y=140, width=60, height=20) addtnoentry = tkinter.Entry(addcourse, width=200) addtnoentry.place(x=195, y=140, width=80, height=20) addsuccessentry = tkinter.Entry(addcourse, width=200, state='normal') addsuccessentry.place(x=140, y=170, width=135, height=20) buttonadd = tkinter.Button(addcourse, text="新增", command=addonecourse) buttonadd.place(x=140, y=200, width=50, height=20) buttoncancel = tkinter.Button(addcourse, text="重置", command=addcancel) buttoncancel.place(x=220, y=200, width=50, height=20) addcourse.mainloop() def exitsys(): root.destroy() studentindex = Toplevel() studentindex.title('學生資訊管理系統') x, y = window_info(studentindex) studentindex.geometry("430x505+%d+%d" % (x, y)) studentindex['bg'] = 'dodgerblue' labelname = tkinter.Label(studentindex, text='歡迎使用學生資訊管理系統', bg='dodgerblue', font=("楷體", 20)) labelname.place(x=60, y=30, width=350, height=40) buttonadd = tkinter.Button(studentindex, text="添 加", command=addstudent) buttonadd.place(x=150, y=90, width=100, height=40) buttonadd = tkinter.Button(studentindex, text="查 詢", command=findonestudent) buttonadd.place(x=150, y=140, width=100, height=40) buttonadd = tkinter.Button(studentindex, text="刪 除", command=deletestudent) buttonadd.place(x=150, y=190, width=100, height=40) buttonadd = tkinter.Button(studentindex, text="查詢所有", command=findallstudent) buttonadd.place(x=150, y=240, width=100, height=40) buttonadd = tkinter.Button(studentindex, text="修 改", command=modifystudent) buttonadd.place(x=150, y=290, width=100, height=40) buttonadd = tkinter.Button(studentindex, text="新增課程", command=addcourse) buttonadd.place(x=150, y=340, width=100, height=40) buttonadd = tkinter.Button(studentindex, text="學生選課資訊", command=findselectcourseinfor) buttonadd.place(x=150, y=390, width=100, height=40) buttonadd = tkinter.Button(studentindex, text="退出系統", command=exitsys) buttonadd.place(x=150, y=440, width=100, height=40) studentindex.mainloop() # =============================================================================== def login(): name = entryName.get() pwd = entryPwd.get() connection = conn() cursor = cur(connection) cursor.execute('select * from login') data = list(cursor.fetchall()) print(data) if data == []: tkinter.messagebox.showerror(message="賬號或密碼錯誤!") return 0 for i in data: print(i[0]) print(i[1]) if i[0] == name and i[1] == pwd: managerindex() def forregister(): def loginregister(): if pwdentry.get() == '' or confirmpwdentry.get == '': tkinter.messagebox.showerror(message="請輸入賬號密碼!") elif pwdentry.get() == confirmpwdentry.get(): connection = conn() cursor = cur(connection) try: cursor.execute('insert into login(user,password)values(%s,%s)', (userentry.get(), pwdentry.get())) connection.commit() if registersuccessentry.get() != '': registersuccessentry.delete('0', 'end') registersuccessentry.insert('0', '註冊成功!') else: registersuccessentry.insert('0', '註冊成功!') bottonOk = tkinter.Button(studentregister, text="立即登入", command=registerlogin, bg='dodgerblue') bottonOk.place(x=125, y=230, width=70, height=30) #return userentry.get(), pwdentry.get() except: connection.rollback() if registersuccessentry.get() != '': registersuccessentry.delete('0', 'end') registersuccessentry.insert('0', '註冊失敗!') else: registersuccessentry.insert('0', '註冊失敗!') else: tkinter.messagebox.showerror(message="兩次輸入的密碼不相同!") def registerlogin(): managerindex() studentregister = Toplevel() x, y = window_info(studentregister) studentregister.title('學生資訊管理系統') studentregister.geometry("415x295+%d+%d" % (x, y)) studentregister['bg'] = 'dodgerblue' labelname = tkinter.Label(studentregister, text='註冊學生資訊管理系統', bg='dodgerblue', font=("楷體", 20)) labelname.place(x=60, y=30, width=300, height=40) labelName = tkinter.Label(studentregister, text="賬 號:", bg='dodgerblue', width=80) labelName.place(x=115, y=110, width=80, height=20) userentry = tkinter.Entry(studentregister, width=80) userentry.place(x=210, y=110, width=80, height=20) labelPwd = tkinter.Label(studentregister, text="密 碼:", bg='dodgerblue', width=80) labelPwd.place(x=115, y=135, width=80, height=20) pwdentry = tkinter.Entry(studentregister, width=80) pwdentry.place(x=210, y=135, width=80, height=20) labelPwd = tkinter.Label(studentregister, text="確認密碼:", bg='dodgerblue', width=80) labelPwd.place(x=115, y=160, width=80, height=20) confirmpwdentry = tkinter.Entry(studentregister, width=80) confirmpwdentry.place(x=210, y=160, width=80, height=20) registersuccessentry = tkinter.Entry(studentregister, width=80) registersuccessentry.place(x=125, y=190, width=165, height=20) bottonCancel = tkinter.Button(studentregister, text='註冊', command=loginregister, bg='dodgerblue') bottonCancel.place(x=225, y=230, width=70, height=30) studentregister.mainloop() manager = Toplevel() manager.title(' 管理員端') x, y = window_info(manager) manager.geometry("415x295+%d+%d" % (x, y)) manager['bg'] = 'dodgerblue' varLoginName = tkinter.StringVar() varLoginPwd = tkinter.StringVar() labelname = tkinter.Label(manager, text='歡迎使用學生資訊管理系統', bg='dodgerblue', font=("楷體", 18)) labelname.place(x=60, y=30, width=300, height=40) labelName = tkinter.Label(manager, text="賬 號:", justify=tkinter.RIGHT, bg='dodgerblue', width=80) labelName.place(x=110, y=110, width=80, height=20) labelPwd = tkinter.Label(manager, text="密 碼:", justify=tkinter.RIGHT, bg='dodgerblue', width=80) labelPwd.place(x=110, y=135, width=80, height=20) entryName = tkinter.Entry(manager, width=80, textvariable=varLoginName) entryName.place(x=210, y=110, width=80, height=20) entryPwd = tkinter.Entry(manager, show='*', width=80, textvariable=varLoginPwd) entryPwd.place(x=210, y=135, width=80, height=20) bottonOk = tkinter.Button(manager, text="登入", command=login, bg='dodgerblue') bottonOk.place(x=125, y=170, width=70, height=30) bottonCancel = tkinter.Button(manager, text='註冊', command=forregister, bg='dodgerblue') bottonCancel.place(x=225, y=170, width=70, height=30) manager.mainloop() def studentlogin(): def forstudentregister(): def loginregister(): if pwdentry.get() == '' or confirmpwdentry.get == '': tkinter.messagebox.showerror(message="請輸入賬號密碼!") elif pwdentry.get() == confirmpwdentry.get(): connection = conn() cursor = cur(connection) try: sqlpwd = "update student set loginpwd = %s where sno = %s" cursor.execute(sqlpwd, ( pwdentry.get(),userentry.get())) connection.commit() if registersuccessentry.get() != '': registersuccessentry.delete('0', 'end') registersuccessentry.insert('0', '註冊成功!') else: registersuccessentry.insert('0', '註冊成功!') bottonOk = tkinter.Button(studentregister, text="立即登入", command=registerlogin, bg='dodgerblue') bottonOk.place(x=125, y=230, width=70, height=30) except: connection.rollback() if registersuccessentry.get() != '': registersuccessentry.delete('0', 'end') registersuccessentry.insert('0', '註冊失敗!') else: registersuccessentry.insert('0', '註冊失敗!') else: tkinter.messagebox.showerror(message="兩次輸入的密碼不相同!") return userentry.get() def registerlogin(): studentindex(userentry.get()) studentregister = Toplevel() x, y = window_info(studentregister) studentregister.title('學生資訊管理系統-註冊') studentregister.geometry("415x295+%d+%d" % (x, y)) studentregister['bg'] = 'dodgerblue' labelname = tkinter.Label(studentregister, text='註冊學生資訊管理系統', bg='dodgerblue', font=("楷體", 20)) labelname.place(x=60, y=30, width=300, height=40) labelName = tkinter.Label(studentregister, text="學 號:", bg='dodgerblue', width=80) labelName.place(x=115, y=110, width=80, height=20) userentry = tkinter.Entry(studentregister, width=80) userentry.place(x=210, y=110, width=80, height=20) labelPwd = tkinter.Label(studentregister, text="密 碼:", bg='dodgerblue', width=80) labelPwd.place(x=115, y=135, width=80, height=20) pwdentry = tkinter.Entry(studentregister, width=80) pwdentry.place(x=210, y=135, width=80, height=20) labelPwd = tkinter.Label(studentregister, text="確認密碼:", bg='dodgerblue', width=80) labelPwd.place(x=115, y=160, width=80, height=20) confirmpwdentry = tkinter.Entry(studentregister, width=80) confirmpwdentry.place(x=210, y=160, width=80, height=20) registersuccessentry = tkinter.Entry(studentregister, width=80) registersuccessentry.place(x=125, y=190, width=165, height=20) bottonCancel = tkinter.Button(studentregister, text='註冊', command=loginregister, bg='dodgerblue') bottonCancel.place(x=225, y=230, width=70, height=30) studentregister.mainloop() def studentindex(name): loginingno=name print('sdfsdffds') def showinfor(): def show(): if textshowinformation.get('1.0', 'end') != '': textshowinformation.delete('1.0', 'end') else: print(loginingno) print('swj') connection = conn() cursor = cur(connection) try: cursor.execute('select * from student where sno=%s', (loginingno)) data = list(cursor.fetchone()) textshowinformation.insert('insert', "學生姓名:" + data[0] + "n" + "年齡:" + data[1] + "n" + "學號" + data[2] + "n" + "班級:" + data[3] + "nn") connection.commit() except: connection.rollback() connection.close() cursor.close connection = conn() cursor = cur(connection) try: cursor.execute('select * from student where sno=%s', (loginingno)) data = list(cursor.fetchone()) textshowinformation.insert('insert', "學生姓名:" + data[0] + "n" + "年齡:" + data[1] + "n" + "學號" + data[2] + "n" + "班級:" + data[3] + "nn") connection.commit() except: connection.rollback() connection.close() cursor.close def showinforcancel(): textshowinformation.delete('1.0', 'end') showinformation = Toplevel() showinformation.title('查詢學籍資訊') x, y = window_info(showinformation) showinformation.geometry("415x295+%d+%d" % (x, y)) showinformation['bg'] = 'dodgerblue' labelname = tkinter.Label(showinformation, text='查詢學籍資訊?', bg='dodgerblue') labelname.place(x=5, y=20, width=100, height=20) buttonshow = tkinter.Button(showinformation, text="確定", command=show) buttonshow.place(x=5, y=50, width=50, height=20) textshowinformation = tkinter.scrolledtext.ScrolledText(showinformation, width=60, height=9) textshowinformation.place(x=5, y=80) buttoncancel = tkinter.Button(showinformation, text="清空", command=showinforcancel) buttoncancel.place(x=5, y=210, width=50, height=20) showinformation.mainloop() def findcourseinfor(): def show(): if textshow.get('1.0', 'end') != '': textshow.delete('1.0', 'end') else: connection = conn() cursor = cur(connection) try: cursor.execute('select * from course') data = list(cursor.fetchall()) textshow.insert('insert', "課程號:ttt課程名:ttt教師編號:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'tt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close connection = conn() cursor = cur(connection) try: cursor.execute('select * from course') data = list(cursor.fetchall()) textshow.insert('insert', "課程號:ttt課程名:ttt教師編號:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'ttt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close def searchallcancel(): textshow.delete('1.0', 'end') findall = Toplevel() findall.title('查詢課程資訊') x, y = window_info(findall) findall.geometry("520x295+%d+%d" % (x, y)) findall['bg'] = 'dodgerblue' labelname = tkinter.Label(findall, text='查詢所有課程資訊?', bg='dodgerblue') labelname.place(x=5, y=20, width=100, height=20) buttonshow = tkinter.Button(findall, text="確定", command=show) buttonshow.place(x=5, y=50, width=50, height=20) textshow = tkinter.scrolledtext.ScrolledText(findall, width=75, height=9) textshow.place(x=5, y=80) buttoncancel = tkinter.Button(findall, text="清空", command=searchallcancel) buttoncancel.place(x=5, y=210, width=50, height=20) findall.mainloop() def selectcourse(): def show(): if textshow.get('1.0', 'end') != '': textshow.delete('1.0', 'end') else: connection = conn() cursor = cur(connection) try: cursor.execute('select * from course') data = list(cursor.fetchall()) textshow.insert('insert', "課程號:ttt課程名:ttt教師編號:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'tt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close connection = conn() cursor = cur(connection) try: cursor.execute('select * from course') data = list(cursor.fetchall()) textshow.insert('insert', "課程號:ttt課程名:ttt教師編號:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'ttt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close def searchallcancel(): textshow.delete('1.0', 'end') def select(): connection = conn() cursor = cur(connection) try: cursor.execute('insert into sc values(%s,%s)', (loginingno, entrysearchone.get())) connection.commit() except: if addsuccessentry.get() != '': addsuccessentry.delete('0', 'end') addsuccessentry.insert('0', '選課失敗!') else: addsuccessentry.insert('0', '選課失敗!') connection.rollback() connection.close() cursor.close if addsuccessentry.get() != '': addsuccessentry.delete('0', 'end') addsuccessentry.insert('0', '選課成功!') else: addsuccessentry.insert('0', '選課成功!') def addcancel(): entrysearchone.delete('0', 'end') addsuccessentry.delete('0', 'end') findall = Toplevel() findall.title('學生選課') x, y = window_info(findall) findall.geometry("520x325+%d+%d" % (x, y)) findall['bg'] = 'dodgerblue' labelname = tkinter.Label(findall, text='查詢所有課程資訊?', bg='dodgerblue') labelname.place(x=5, y=20, width=100, height=20) buttonshow = tkinter.Button(findall, text="確定", command=show) buttonshow.place(x=5, y=50, width=50, height=20) textshow = tkinter.scrolledtext.ScrolledText(findall, width=75, height=9) textshow.place(x=5, y=80) labelname = tkinter.Label(findall, text='請輸入課程編號:', bg='dodgerblue') labelname.place(x=5, y=210, width=100, height=20) entrysearchone = tkinter.Entry(findall, width=200) entrysearchone.place(x=5, y=240, width=150, height=20) addsuccessentry = tkinter.Entry(findall, width=200) addsuccessentry.place(x=5, y=270, width=75, height=20) buttoncancel = tkinter.Button(findall, text="選擇", command=select) buttoncancel.place(x=5, y=300, width=50, height=20) buttoncancel = tkinter.Button(findall, text="重置", command=addcancel) buttoncancel.place(x=105, y=300, width=50, height=20) findall.mainloop() def findselectcourseinfor(): def show(): print('swj') if textshow.get('1.0', 'end') != '': textshow.delete('1.0', 'end') else: connection = conn() cursor = cur(connection) try: cursor.execute('select sno,sname,sclass,cno,cname from student,course where student.sno=sc.sno and course.cno=sc.cno and sno=%s',(loginingno)) data = list(cursor.fetchall()) textshow.insert('insert', "學號:tt姓名:tt班級:tt課程編號:tt課程名:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'tt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close connection = conn() cursor = cur(connection) try: cursor.execute('select sc.sno,sname,sclass,sc.cno,course.cname from student,course,sc where student.sno=sc.sno and course.cno=sc.cno and sc.sno=%s',(loginingno)) data = list(cursor.fetchall()) textshow.insert('insert', "學號:tt姓名:tt班級:tt課程編號:tt課程名:") textshow.insert('insert', "n") for i in data: print(i) textshow.insert('insert', 'tt'.join(i)) textshow.insert('insert', "n") except: connection.rollback() connection.close() cursor.close def searchallcancel(): textshow.delete('1.0', 'end') findall = Toplevel() findall.title('查詢選課資訊') x, y = window_info(findall) findall.geometry("520x295+%d+%d" % (x, y)) findall['bg'] = 'dodgerblue' labelname = tkinter.Label(findall, text='查詢選課資訊?', bg='dodgerblue') labelname.place(x=5, y=20, width=100, height=20) buttonshow = tkinter.Button(findall, text="確定", command=show) buttonshow.place(x=5, y=50, width=50, height=20) textshow = tkinter.scrolledtext.ScrolledText(findall, width=105, height=9) textshow.place(x=5, y=80) buttoncancel = tkinter.Button(findall, text="清空", command=searchallcancel) buttoncancel.place(x=5, y=210, width=50, height=20) findall.mainloop() print(3) indexofstudent = Toplevel() indexofstudent.title('學生資訊管理系統-學生') x, y = window_info(indexofstudent) indexofstudent.geometry("430x425+%d+%d" % (x, y)) indexofstudent['bg'] = 'dodgerblue' labelname = tkinter.Label(indexofstudent, text='歡迎使用學生資訊管理系統', bg='dodgerblue', font=("楷體", 20)) labelname.place(x=60, y=30, width=350, height=40) buttonadd = tkinter.Button(indexofstudent, text="查詢學籍資訊", command=showinfor) buttonadd.place(x=150, y=90, width=100, height=40) buttonadd = tkinter.Button(indexofstudent, text="查詢課程資訊", command=findcourseinfor) buttonadd.place(x=150, y=140, width=100, height=40) buttonadd = tkinter.Button(indexofstudent, text="選 課", command=selectcourse) buttonadd.place(x=150, y=190, width=100, height=40) buttonadd = tkinter.Button(indexofstudent, text="查詢選課資訊", command=findselectcourseinfor) buttonadd.place(x=150, y=240, width=100, height=40) buttonadd = tkinter.Button(indexofstudent, text="退出系統", command=exitsys) buttonadd.place(x=150, y=290, width=100, height=40) indexofstudent.mainloop() def login(): name = entryName.get() pwd = entryPwd.get() connection = conn() cursor = cur(connection) cursor.execute('select * from student') data = list(cursor.fetchall()) print(data) if data == []: tkinter.messagebox.showerror(message="賬號或密碼錯誤!") return 0 for i in data: print(i[2]) print(i[4]) if i[2] == name and i[4] == pwd: studentindex(name) student = Toplevel() student.title(' 登入-學生端') x, y = window_info(student) student.geometry("415x295+%d+%d" % (x, y)) student['bg'] = 'dodgerblue' labelname = tkinter.Label(student, text='歡迎使用學生資訊管理系統', bg='dodgerblue', font=("楷體", 18)) labelname.place(x=60, y=30, width=300, height=40) labelName = tkinter.Label(student, text="學 號:", bg='dodgerblue', width=80) labelName.place(x=110, y=110, width=80, height=20) labelPwd = tkinter.Label(student, text="密 碼:", bg='dodgerblue', width=80) labelPwd.place(x=110, y=135, width=80, height=20) entryName = tkinter.Entry(student, width=80, textvariable=varLoginName) entryName.place(x=210, y=110, width=80, height=20) entryPwd = tkinter.Entry(student, show='*', width=80, textvariable=varLoginPwd) entryPwd.place(x=210, y=135, width=80, height=20) bottonOk = tkinter.Button(student, text="登入", command=login, bg='dodgerblue') bottonOk.place(x=125, y=170, width=70, height=30) bottonCancel = tkinter.Button(student, text='註冊', command=forstudentregister, bg='dodgerblue') bottonCancel.place(x=225, y=170, width=70, height=30) student.mainloop() root=tkinter.Tk(className=' 學生資訊管理系統') x,y=window_info(root) root.geometry("415x295+%d+%d"%(x,y)) root['bg']='dodgerblue' varLoginName=tkinter.StringVar() varLoginPwd=tkinter.StringVar() labelname = tkinter.Label(root, text='歡迎使用學生資訊管理系統', bg='dodgerblue', font=("楷體", 18)) labelname.place(x=60, y=30, width=300, height=40) bottonOk=tkinter.Button(root,text="學生登入",command=studentlogin,bg='dodgerblue') bottonOk.place(x=150,y=140,width=100,height=40) bottonCancel=tkinter.Button(root,text='管理員登入',command=teacherlogin,bg='dodgerblue') bottonCancel.place(x=150,y=200,width=100,height=40) def createdatabase(): conn = pymysql.connect("localhost", "root", "root") cur = conn.cursor() cur.execute('create database if not exists sch') def createtable(): connection = conn() cursor = cur(connection) sqlstudent="""create table if not exists student( sname char(45) not null, sage char(45), sno char(45) primary key, sclass char(45), loginpwd char(45) )engine=innodb""" cursor.execute(sqlstudent) sqllogin="""create table if not exists login( user char(45)primary key, password char(45) not null )engine=innodb""" cursor.execute(sqllogin) connection.commit() cursor.execute("""insert into login(user,password) values('user','pwd')""") connection.commit() sqlteacher="""create table if not exists teacher( tno char(45) primary key, tname char(45) )engine=innodb""" cursor.execute(sqlteacher) connection.commit() sqlcourse="""create table if not exists course( cno char(45) , cname char(45), tno char(45), constraint pk_course primary key (cno,tno) )engine=innodb""" cursor.execute(sqlcourse) connection.commit() sqlsc="""create table if not exists sc( sno char(45), cno char(45), constraint pk_sc primary key (sno,cno) )engine=innodb""" cursor.execute(sqlsc) connection.commit() createdatabase() createtable() root.mainloop()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45