返回顶部
首页 > 资讯 > 后端开发 > Python >python tkinter怎么实现学生信息管理系统
  • 271
分享到

python tkinter怎么实现学生信息管理系统

2023-06-29 07:06:19 271人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

这篇文章给大家分享的是有关python tkinter怎么实现学生信息管理系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。具体内容如下初学Python,代码写的比较繁杂,系统功能还有完善的空间系统使用

这篇文章给大家分享的是有关python tkinter怎么实现学生信息管理系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体内容如下

初学Python,代码写的比较繁杂,系统功能还有完善的空间

系统使用了mysql数据库数据库:sch,用户名:root ,密码:123456,创建表的语句写在代码里面了

import tkinterimport tkinter.messageboximport reimport pyMysqlfrom tkinter import scrolledtextimport osfrom 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 curdef 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怎么实现学生信息管理系统”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

--结束END--

本文标题: python tkinter怎么实现学生信息管理系统

本文链接: https://lsjlt.com/news/323499.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • python tkinter怎么实现学生信息管理系统
    这篇文章给大家分享的是有关python tkinter怎么实现学生信息管理系统的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。具体内容如下初学python,代码写的比较繁杂,系统功能还有完善的空间系统使用...
    99+
    2023-06-29
  • python tkinter实现学生信息管理系统
    本文实例为大家分享了python tkinter实现学生信息管理系统的具体代码,供大家参考,具体内容如下 初学python,代码写的比较繁杂,系统功能还有完善的空间 系统使用了mys...
    99+
    2024-04-02
  • python怎么实现学生信息管理系统
    本文将为大家详细介绍“python怎么实现学生信息管理系统”,内容步骤清晰详细,细节处理妥当,而小编每天都会更新不同的知识点,希望这篇“python怎么实现学生信息管理系统”能够给你意想不到的收获,请大家跟着小编的思路慢慢深入,具体内容如下...
    99+
    2023-06-06
  • 用python实现学生信息管理系统
    用Python实现学生信息管理系统,供大家参考,具体内容如下 系统功能有: 1.录入,查找,删除,修改学生信息2.学生成绩排名3.显示全部学生信息 代码如下: filename = ...
    99+
    2024-04-02
  • 怎么使用python实现学生信息管理系统
    本文将为大家详细介绍“怎么使用python实现学生信息管理系统”,内容步骤清晰详细,细节处理妥当,而小编每天都会更新不同的知识点,希望这篇“怎么使用python实现学生信息管理系统”能够给你意想不到的收获,请大家跟着小编的思路慢慢深入,具体...
    99+
    2023-06-06
  • python学生信息管理系统实现代码
    python实现学生信息管理系统,供大家参考,具体内容如下 #!/usr/bin/env python # -*- coding:utf-8 -*- import re impo...
    99+
    2024-04-02
  • python代码实现学生信息管理系统
    本文实例为大家分享了python实现学生信息管理系统的具体代码,含代码注释、增删改查、排序、统计显示学生信息,供大家参考,具体内容如下 运行如下: 具体代码如下: # _*_ co...
    99+
    2024-04-02
  • python怎么实现简易的学生信息管理系统
    一、系统功能1.录入学生信息2.查找学生信息3.修改学生信息4.删除学生信息5.成绩排序6.统计学生总人数7.显示所有学生信息0.退出系统二、系统开发环境1.操作系统:win72.开发工具:PyCharm3.Python内置模块:os,re...
    99+
    2023-05-14
    Python
  • java怎样实现学生信息管理系统
    这篇文章将为大家详细讲解有关java怎样实现学生信息管理系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。具体内容如下 import java.util.Scanner;//导入jav...
    99+
    2023-05-30
    java
  • Python之学生信息管理系统
    目录 一、基础界面实现  1、主函数 2、保持循环,获取用户需求  二、函数实现模块功能 1、添加学生信息 2、删除学生信息  3、修改学生信息 4、查找全部学生信息 5、退出系统 三、整合代码 1、 完整代码 2、完整实现过程 实现 ...
    99+
    2023-08-31
    python
  • Python实现简单的学生信息管理系统
    本文实例为大家分享了Python实现学生信息管理系统的具体代码,供大家参考,具体内容如下 要求描述: 学生的信息包括:学号,姓名,年龄,性别,出生日期,地址,电话,E-mail等等。...
    99+
    2024-04-02
  • python实现简易的学生信息管理系统
    目录一、系统功能二、系统开发环境三、实现代码四、项目打包并生成.exe可执行文件本文实例为大家分享了python实现简易学生信息管理系统的具体代码,供大家参考,具体内容如下 一、系统...
    99+
    2024-04-02
  • JavaScript+HTML实现学生信息管理系统
    目录一、前言二、效果图三、代码四、学生信息管理系统主界面一、前言 用数组来存储所有学生对象的信息,实现了双向更新,初始时(数组内的对象信息“填充界面”),后面的界面操作可以更新数组内...
    99+
    2024-04-02
  • JavaWeb实现学生信息管理系统(1)
    这是一个很简单的学生信息管理系统,会用到很多小知识,比如说: 数据库连接池 DBUtils JSP、EL、JSTL MVC设计模式 JavaWeb...
    99+
    2024-04-02
  • JavaWeb实现学生信息管理系统(2)
    本文接着上一篇,继续为大家分享了JavaWeb实现学生信息管理系统的第二篇,供大家参考,具体内容如下 今日任务:实现学生管理系统的查找和添加功能! 一、查询学生信息 1. index...
    99+
    2024-04-02
  • JavaWeb实现学生信息管理系统(3)
    本文接着第二篇,继续为大家分享了JavaWeb实现学生信息管理系统,供大家参考,具体内容如下 今日任务:实现学生管理系统的删除、更新、修改和模糊查询功能! 一、删除学生信息 点击超链...
    99+
    2024-04-02
  • java+sqlserver实现学生信息管理系统
    目录一.实现效果二.实现代码1.DBUtil.java2.操作程序test.java前提: 1.建立了与sqlserver数据库的连接(JTDS连接sqlserver数据库的包jtd...
    99+
    2024-04-02
  • python面向对象怎么实现学生信息管理系统
    今天小编给大家分享一下python面向对象怎么实现学生信息管理系统的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。1.主要内容...
    99+
    2023-06-30
  • C++实现学生信息管理系统(Map实现)
    本文实例为大家分享了C++实现学生信息管理系统的具体代码,供大家参考,具体内容如下 1、 作品的功能描述: 实现一个学生信息管理系统,通过对学生信息类中的成员进行增、删、改、查从而实...
    99+
    2024-04-02
  • 学生信息系统(python实现)
    #coding=utf-8import os.pathfilename='student.txt'def menm():#菜单界面 print('===========================学生管理系统==========...
    99+
    2023-09-14
    python 开发语言
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作