您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關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] + "\n\n") 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] + "\n\n") 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', "姓名:\t\t年齡:\t\t學號:\t\t班級:") textdelete.insert('insert', "\n") for i in data: print(i) textdelete.insert('insert', '\t\t'.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', "姓名:\t\t年齡:\t\t學號:\t\t班級:") textdelete.insert('insert', "\n") for i in data: print(i) textdelete.insert('insert', '\t\t'.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', "姓名:\t\t年齡:\t\t學號:\t\t班級:\t\t登錄密碼:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t'.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', "姓名:\t\t年齡:\t\t學號:\t\t班級:\t\t登錄密碼:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t'.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', "學號:\t\t姓名:\t\t班級:\t\t課程編號:\t\t課程名:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t'.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', "學號:\t\t姓名:\t\t班級:\t\t課程編號:\t\t課程名:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t'.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] + "\n\n") 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] + "\n\n") 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', "課程號:\t\t\t課程名:\t\t\t教師編號:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t'.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', "課程號:\t\t\t課程名:\t\t\t教師編號:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t\t'.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', "課程號:\t\t\t課程名:\t\t\t教師編號:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t'.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', "課程號:\t\t\t課程名:\t\t\t教師編號:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t\t'.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', "學號:\t\t姓名:\t\t班級:\t\t課程編號:\t\t課程名:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t'.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', "學號:\t\t姓名:\t\t班級:\t\t課程編號:\t\t課程名:") textshow.insert('insert', "\n") for i in data: print(i) textshow.insert('insert', '\t\t'.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()
感謝各位的閱讀!關于“python tkinter怎么實現學生信息管理系統”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。