简单基于python的GUI学生信息管理系统(链接数据库)

简单基于python的学生信息管理系统

完成情况:有超过6个的前端页面,实现了与MySQL数据库的连接。已基本完成基本要求下的全部内容:必须完成学生信息表中的下面功能(学生信息表中包括学号、姓名、性别、班级、出生日期、联系方式、家庭住址等信息)
①插入:将某学生的基本信息插入到信息表中;
②查询:查找满足条件的学生。要求提供多种不同的查询方式,包括按照学号查询,按 照 姓名查询,按照联系方式查询等。
③修改:对基本信息的数据项进行修改。要求可以选择的某一项信息进行修改,修改姓名,修改联系方式,修改家庭住址等。
④浏览:将登记表中的全部基本信息输出浏览。以及按照满足指定条件的学生的全部基本信息输出,例如输出指定班级的全部学生。
⑤删除:将满足条件的基本信息删除。包括按照学号删除,按照姓名删除。要求删除前,先按照学号或者姓名查找需要删除的学生,如果找不到则给出对应的提示 信息。
并且完成了提高要求下的排序功能,增加学生成绩信息,把学生成绩按降序排序。插入学生信息时,若该学号已存在,给出了错误提示。查询、修改和删除时,若查询的学生不存在,给出了查询不到等提示。

主页面:

from tkinter import *
import tkinter as tk
import tkinter.messagebox #消息框
import AddStudent as AS
import Delete as DE
import Update as UP
import Find as F
import database as q
import Sexfind as SF
import sorsub as sb


class Mian:
    def __init__(self):
        root = Tk()
        root.title('华南理工大学学生信息管理系统   作者:南瓜头777;版本:1.0;时间:2020.08.22')
        logo = PhotoImage(file = "F:/南瓜头777/图片1.png")
        Label(root,image=logo,height=100,bg='LightBlue').grid(row=0,column=1)

        def add():
            AS.AddStudent()
        def edit():
            UP.Update()
        def dele():
            DE.Delete()
        def find():
            F.Find()

        def sfind():
            SF.Sexfind()

        def ss():
            sb.Sorsub()

        def queryall():
            text.delete('1.0','end') #从第一行开始,全部删除
            number=0
            list=['学号:','姓名:','年龄:','性别:','班级:','电话:','地址:']
            result=q.QueryAll()
            # print(result)
            for items in result:
                for index,item in enumerate(items):
                    message=list[index]+str(item)+' '
                    text.insert(INSERT,message)
                    number+=1
                    if number==7:
                        text.insert(INSERT,'\n')
                        number=0
            tk.messagebox.showinfo('提示', '显示成功!')

        def queryall2():
            text.delete('1.0','end') #从第一行开始,全部删除
            number=0
            list=['序号:','班级:','人数:']
            result=q.QueryAll2()
            # print(result)
            for items in result:
                for index,item in enumerate(items):
                    message=list[index]+str(item)+' '
                    text.insert(INSERT,message)
                    number+=1
                    if number==3:
                        text.insert(INSERT,'\n')
                        number=0
            tk.messagebox.showinfo('提示', '显示成功!')

        def queryall3():
            text.delete('1.0','end') #从第一行开始,全部删除
            number=0
            list=['学号:','姓名:','C语言:','java:','python:']
            result=q.QueryAll3()
            # print(result)
            for items in result:
                for index,item in enumerate(items):
                    message=list[index]+str(item)+' '
                    text.insert(INSERT,message)
                    number+=1
                    if number==5:
                        text.insert(INSERT,'\n')
                        number=0
            tk.messagebox.showinfo('提示', '显示成功!')

        Button(root, text='ID/姓名\n查询', width=10, height=2,bg='LightBlue',command=find).grid(row=1,column=6,sticky=W)
        Button(root, text='添加学生', width=10,height=2,bg='LightBlue',command=add).grid(row=1,column=2,sticky=W)
        Button(root, text='编辑学生', width=10,height=2,bg='LightBlue',command=edit).grid(row=1,column=3,sticky=W)
        Button(root, text='成绩排序', width=10, height=2,bg='LightBlue',command=ss).grid(row=1, column=4, sticky=W)
        Button(root, text='删除学生', width=10,height=2,bg='LightBlue',command=dele).grid(row=1,column=7,sticky=N)
        Button(root, text='性别查询', width=10, height=2,bg='LightBlue',command=sfind).grid(row=2, column=6, sticky=W)
        Button(root, text='显示全部\n基本信息', width=10,height=2,bg='LightBlue',command=queryall).grid(row=2, column=2,sticky=W)
        Button(root, text='显示全部\n班级信息', width=10,height=2,bg='LightBlue',command=queryall2).grid(row=2, column=3,sticky=W)
        Button(root, text='显示全部\n学生成绩', width=10, height=2,bg='LightBlue',command=queryall3).grid(row=2, column=4, sticky=W)

        text=tk.Text()
        text.grid(row=3, column=0)
        mainloop()
if __name__=='__main__':
    Mian()

添加学生信息:

from tkinter import  *
import database as add
class AddStudent:
    def __init__(self):
        root=Tk()
        root.title('新增学生')
        Label(root, text='学号:').grid(row=0)
        Label(root, text='姓名:').grid(row=1)
        Label(root, text='年龄:').grid(row=2)
        Label(root, text='性别:').grid(row=3)
        Label(root, text='班级:').grid(row=4)
        Label(root, text='电话:').grid(row=5)
        Label(root, text='地址:').grid(row=6)

        id=Entry(root,textvariable=StringVar())
        name=Entry(root,textvariable=StringVar())
        age=Entry(root,textvariable=StringVar())
        gender = Entry(root, textvariable=StringVar())
        cla = Entry(root, textvariable=StringVar())
        phone = Entry(root, textvariable=StringVar())
        address = Entry(root, textvariable=StringVar())

        id.grid(row=0, column=1, padx=10, pady=10)
        name.grid(row=1, column=1, padx=10, pady=5)
        age.grid(row=2, column=1, padx=10, pady=5)
        gender.grid(row=3, column=1, padx=10, pady=5)
        cla.grid(row=4, column=1, padx=10, pady=5)
        phone.grid(row=5, column=1, padx=10, pady=5)
        address.grid(row=6, column=1, padx=10, pady=5)

        def adds():
            sid=int(id.get())
            sname=name.get()
            sage=int(age.get())
            sgender = gender.get()
            scla = cla.get()
            sphone = int(phone.get())
            saddress = address.get()

            add.Add(sid, sname, sage, sgender, scla, sphone, saddress)

            id.delete(0, END)
            name.delete(0, END)
            age.delete(0, END)
            gender.delete(0, END)
            cla.delete(0, END)
            phone.delete(0, END)
            address.delete(0, END)
        Button(root,text='添加',width=10,command=adds).grid(row=7,column=0,sticky=W,padx=10,pady=5)
        Button(root,text='取消',width=10,command=root.quit).grid(row=7,column=1,sticky=E,padx=10,pady=5)
        mainloop()
if __name__=='__main__':
    AddStudent()

连接数据库

import pymysql
import tkinter as tk
import  tkinter.messagebox
# 打开数据库
db=pymysql.connect('localhost','root','root','pyproject',charset='utf8')
# 使用cursor()方法获取操作游标
cursor=db.cursor()


def IsExists(id):
    sql="select * from students where id=%s"
    # 使用execute方法执行SQL语句
    cursor.execute(sql,id)
    result=cursor.rowcount
    if result:
        return True
    else:
        return False

def Add(id,name,age,gender,cla,phone,address):
    if(IsExists(id)==True):
        print('该学生已存在')
        tk.messagebox.showwarning('提示','该学生已存在')
    else:
        sql="insert into  students values(%s,%s,%s,%s,%s,%s,%s)"
        cursor.execute(sql,(id,name,age,gender,cla,phone,address))
        result=cursor.rowcount
        if result:
            print('添加成功')
            tk.messagebox.showinfo('提示','添加成功!')
        else:
            print('添加失败')
            tk.messagebox.showerror('提示','添加失败!')

def Delete(id):
    if(IsExists(id)==True):
        sql="delete from students where id=%s"
        cursor.execute(sql,id)
        result=cursor.rowcount
        if result:
            print('删除成功')
            tk.messagebox.showinfo('提示','删除成功!')
        else:
            print('删除失败')
            tk.messagebox.showerror('提示','删除失败!')
    else:
        print('该学生不存在')
        tk.messagebox.showwarning('提示','该学生不存在!')

def Update(id,name,age,gender,cla,phone,address):
    if(IsExists(id)==True):
        sql='update students set name=%s,age=%s,gender=%s,cla=%s,phone=%s,address=%s where id=%s'
        cursor.execute(sql,(name,age,gender,cla,phone,address,id))
        result=cursor.rowcount
        if result:
            print('修改成功')
            tk.messagebox.showinfo('提示','修改成功!')
        else:
            print('修改失败')
            tk.messagebox.showerror('提示','修改失败!')
    else:
        print('未查询到该学生')
        tk.messagebox.showwarning('提示','未查询到该学生!')



def Query(id):
    sql="select * from students where id =%s"
    cursor.execute(sql,id)
    result=cursor.fetchone()
    # print(result)
    return result

def Queryname(name):
    sql="select * from students where name =%s"
    cursor.execute(sql,name)
    result=cursor.fetchone()
    # print(result)
    return result

def findsex(sex):
    sql="select * from students where gender =%s"
    cursor.execute(sql,sex)
    result=cursor.fetchall()
    # print(result)
    return result

def QueryAll():
    #list=['学号:','姓名:','年龄:'...:']
    sql="select * from students"
    cursor.execute(sql)
    result=cursor.fetchall()
    #for items in result:
       # for index,item in enumerate(items):
      #      print(list[index],item,end='')
     #   print('\n')
    #print(result)
    return result

def QueryAll2():
    sql="select * from class"
    cursor.execute(sql)
    result=cursor.fetchall()
    return result

def QueryAll3():
    sql="select * from grade"
    cursor.execute(sql)
    result=cursor.fetchall()
    return result

def QueryAll4():
    sql="select * from grade order by python desc"
    cursor.execute(sql)
    result=cursor.fetchall()
    return result
def QueryAll5():
    sql="select * from grade order by C desc"
    cursor.execute(sql)
    result=cursor.fetchall()
    return result
def QueryAll6():
    sql="select * from grade order by java desc"
    cursor.execute(sql)
    result=cursor.fetchall()
    return result

QueryAll()

删除学生信息

from tkinter import *
import database as delete
class Delete:
    def __init__(self):
        root = Tk()
        root.title('删除学生')
        Label(root, text='学号:').grid(row=0)
        id = Entry(root, textvariable=StringVar())
        id.grid(row=0, column=1, padx=10, pady=10)
        def deles():
            sid = int(id.get())
            delete.Delete(sid)
            id.delete(0,END)
        Button(root, text='删除', width=10, command=deles).grid(row=7, column=0, sticky=W, padx=10, pady=5)
        Button(root, text='取消', width=10,command=root.quit).grid(row=7, column=1, sticky=E, padx=10, pady=5)
        mainloop()
if __name__ == '__main__':
    Delete()

查找学生信息

from tkinter import *
import database as find
import tkinter as tk

class Find:
    def __init__(self):
        root = Tk()
        root.title('查询学生')
        Label(root, text='学号/姓名:').grid(row=0)
        id = Entry(root, textvariable=StringVar())
        id.grid(row=0, column=1, padx=10, pady=10)

        def queryid():
            text.delete('1.0', 'end')  # 从第一行开始,全部删除
            number = 0
            list = ['学号:', '姓名:', '年龄:', '性别:', '班级:', '电话:', '地址:']
            result = Find()
            print(result)
            if result:
                for index, item in enumerate(result):
                    message = list[index] + str(item) + '  '
                    text.insert(INSERT, message)
                    number += 1
                    if number == 7:
                        text.insert(INSERT, '\n')
                        number = 0
                tk.messagebox.showinfo('提示', '显示成功!')
            else:
                print("查无此人")
                tk.messagebox.showwarning('提示', '未查询到该学生!')
        def queryname():
            text.delete('1.0', 'end')  # 从第一行开始,全部删除
            number = 0
            list = ['学号:','姓名:','年龄:','性别:','班级:','电话:','地址:']
            result = Find2()
            print(result)
            if result:
                for index,item in enumerate(result):
                    message=list[index]+str(item)+'  '
                    text.insert(INSERT,message)
                    number+=1
                    if number==7:
                        text.insert(INSERT,'\n')
                        number=0
                tk.messagebox.showinfo('提示', '显示成功!')
            else:
                print("查无此人")
                tk.messagebox.showwarning('提示', '未查询到该学生!')

        def Find():
            sid = int(id.get())
            #print(sid)
            result =find.Query(sid)
            print(result)
            return result
            id.delete(0,END)

        def Find2():
            sname = str(id.get())
            # print(sname)
            result = find.Queryname(sname)
            print(result)
            return result
            id.delete(0,END)

        Button(root, text='ID查询', width=10, command=queryid).grid(row=7, column=0, sticky=W, padx=10, pady=5)
        Button(root, text='姓名查询', width=10, command=queryname).grid(row=7, column=2, sticky=W, padx=10, pady=5)
        Button(root, text='取消', width=10,command=root.quit).grid(row=7, column=3, sticky=E, padx=10, pady=5)
        text = tk.Text()
        text.grid(row=3, column=1)
        mainloop()


if __name__ == '__main__':
    Find()

通过性别查询

from tkinter import *
import database as find
import tkinter as tk

class Sexfind:
    def __init__(self):
        root = Tk()
        root.title('查询学生')
        Label(root, text='性别:').grid(row=0)
        gender = Entry(root, textvariable=StringVar())
        gender.grid(row=0, column=1, padx=10, pady=10)

        def querysex():
            text.delete('1.0', 'end')  # 从第一行开始,全部删除
            number = 0
            list = ['学号:', '姓名:', '年龄:', '性别:', '班级:', '电话:', '地址:']
            result = Find()
            print(result)
            if result:
                for items in result:
                    for index, item in enumerate(items):
                        message = list[index] + str(item) + '  '
                        text.insert(INSERT, message)
                        number += 1
                        if number == 7:
                            text.insert(INSERT, '\n')
                            number = 0
                tk.messagebox.showinfo('提示', '显示成功!')
            else:
                print("查无此人")
                tk.messagebox.showwarning('提示', '未查询到该学生!')

        def Find():
            sgender = str(gender.get())
            result =find.findsex(sgender)
            #print(result)
            return result
            id.delete(0,END)

        Button(root, text='性别查询', width=10, command=querysex).grid(row=7, column=0, sticky=W, padx=10, pady=5)
        Button(root, text='取消', width=10,command=root.quit).grid(row=7, column=1, sticky=E, padx=10, pady=5)
        text = tk.Text()
        text.grid(row=4, column=0)
        mainloop()


if __name__ == '__main__':
    Sexfind()

其他还实现了成绩排序功能,修改学生信息和数据库文件(sql)。

部分效果图
简单基于python的GUI学生信息管理系统(链接数据库)_第1张图片

简单基于python的GUI学生信息管理系统(链接数据库)_第2张图片
简单基于python的GUI学生信息管理系统(链接数据库)_第3张图片
**

关注公众号,回复“学生信息”,获取全部源码(#.#)

**

喜欢就留下一个赞吧!!!!!!!

你可能感兴趣的:(学生信息管理系统,python,数据库,mysql,tkinter,1024程序员节)