栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

基于PythonTK 窗口MYSQL的图书管理系统

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于PythonTK 窗口MYSQL的图书管理系统

该图书管理系统实现了用户、管理员界面的图书管理系统;在用户界面实现了查询图书、借阅图书、归还图书、捐赠图书、图书馆信息的功能。在管理员界面实现了打印缺的书单、下架图书、查询借阅记录、新进图书、查询图书信息等操作,代码简单易懂。

废话不多说直接展示Mysql中的部分表

mysql表格
读者学号密码性别班级
管理者职工号密码性别院系
书籍编号作者数量出版日期
借阅学号书号借出时间归还时间
读者号账号密码
管理号账号密码
读者姓名性别学院班级

mysql数据库代码如下:

create database library;
use library;

create table reader(rid int primary key,
rname char(20) not null ,
rsex char(5) not null,
class char(20),
bleft int);

create table managers(rid int primary key,
mname char(20) not null,
msex char(5) not null,
mclass char(20),
mbleft int);

create table book(bid int,
writer char(20),
num int ,
bname char(20) not null,
ptime datetime );

create table borrow(lid int,
rid int,
bid int primary key,
btime datetime ,
rtime datetime  
);
create table rpass(rid int primary key,
rpassward char(10) not null  
);
create table mpass(
mid int primary	key,
mpassward char(10)  not null );

create table reader_mess(rid int,
mingzi char(20)  ,
rsex char(5) ,
xueyuan char(50)not null,
class char(20),
bleft int
);
create table lib_mess(iname char(20) not null,
iadress char(10));

 接着往下看

 

该系统是基于Python中的pyMySQL、TK 窗口完成、参考时注意修改图片位置和mysql数据库的账户密码。

这里是主界面

import tkinter as tk
import tkinter.messagebox as msg
import pymysql
import os
import user
import manage
from tkinter import  *

BACK_PATH="D:pycharmgou.gif"

def exit1():
    root.destroy()
    user.frame()

def exit2():
    root.destroy()
    manage.frame()

def frame():
    global root
    root = tk.Tk()
    root.title('科B311图书系统')
    photo=tk.PhotoImage(file=BACK_PATH)
    theLabel = tk.Label(root, image=photo, compound=tk.CENTER, fg="white").grid(row=0, column=0)
    theLabel2 = tk.Label(root, image=photo, compound=tk.CENTER, fg="white").grid(row=0, column=2)
    labe1 = tk.Label(root, text="欢迎来到科B311图书系统,请选择用户类型:", font=36).grid(row=0, column=1)
    tk.Button(root, text='普通用户',width=10,height=2,command=exit1).grid(row=1, column=1,)
    tk.Button(root, text='管理员',width=10,height=2,  command=exit2).grid(row=2, column=1)
    root.mainloop()


if __name__ == '__main__':
    frame()

其次是管理员界面 manage.py

import tkinter as tk
import tkinter.messagebox as msg
import pymysql
import os
import user

BACK_PATH="D:pycharmhorse.gif"


def check_book():
    db = pymysql.connect(host="localhost", user="root", password="123456", db="library")
    cursor = db.cursor()
    a = input_book.get()
    sql = "SELECt * FROM book WHERe bname = '%s'" % (a)
    cursor.execute(sql)
    results = cursor.fetchone()
    if results:
        root3 = tk.Tk()
        root3.title('查询到的书')
        val = "您要查询的书号为:%s" % (results[0])
        print2 = tk.Label(root3, text=val)
        print2.grid(row=1, column=0, padx=10, pady=5)
        val = "您要查询的书的作者为:%s" % (results[1])
        print3 = tk.Label(root3, text=val)
        print3.grid(row=2, column=0, padx=10, pady=5)
        val = "您要查询的书的库存量为:%s" % (results[2])
        print4 = tk.Label(root3, text=val)
        print4.grid(row=3, column=0, padx=10, pady=5)
        val = "您要查询的书名为:%s" % (results[3])
        print5 = tk.Label(root3, text=val)
        print5.grid(row=4, column=0, padx=10, pady=5)
        val = "您要查询的书的出版日期为:%s" % (results[4])
        print6 = tk.Label(root3, text=val)
        print6.grid(row=5, column=0, padx=10, pady=5)
    else:
        msg._show(title='错误', message='没有查到您要查询的记录')
    db.close()

def book_print():
    db = pymysql.connect(host="localhost", user="root", password="123456", db="library")
    cursor = db.cursor()
    sql = "SELECt bname FROM book WHERe num=0"
    cursor.execute(sql)
    results = cursor.fetchall()
    for i in results:
        print("库存量不足的书名为:"+i[0])
    db.close()

def delete_end():
    db = pymysql.connect(host="localhost", user="root", password="123456", db="library")
    cursor = db.cursor()
    name = input4.get()
    sql = "UPDATE book SET num=0 WHERe bname= '%s'"%(name)
    try:
        cursor.execute(sql)
        db.commit()
        msg._show(title='成功', message='下架成功')
    except:
        db.rollback()
        msg._show(title='系统故障', message='下架失败')
    db.close()


def resiger_end():
    db = pymysql.connect(host="localhost", user="root",passwd= "123456", db="library")
    cursor = db.cursor()
    rid = input1.get()
    name = input2.get()
    sex = input3.get()
    clas = input4.get()
    sql1 = " INSERT INTO mpass VALUES(%s,%s)"%(rid,name)
    sql = "INSERT INTO managers VALUES(%s,'%s','%s','%s',10)" % (rid, name, sex, clas)
    try:
        cursor.execute(sql)
        db.commit()
        cursor.execute(sql1)
        db.commit()
        msg._show(title='成功', message='注册成功!')
    except:
        msg._show(title='错误', message='注册失败!')
    db.close()

def borrow_end():
    global root3
    root3 = tk.Tk()
    root3.title("借阅记录查询:")
    db = pymysql.connect(host="localhost", user="root", password="123456", db="library")
    cursor = db.cursor()
    name = input5.get()
    sql = "SELECT lid,bname,btime,rtime,mingzi FROM borrow,reader,book,reader_mess WHERe borrow.bid=book.bid And reader.rid=reader_mess.rid AND borrow.rid=reader.rid AND rname='%s'"%(name)
    cursor.execute(sql)
    results = cursor.fetchall()
    cur=0
    for i in results:
      tk.Label(root3,text="记录号为:%s 书名为:%s 借阅时间为:%s 还书时间为:%s 名字叫:%s"%(i[0],i[1],i[2],i[3],i[4]),justify=tk.LEFT,font=36).grid(row=cur,column=0)
      cur=cur+1
    db.close()

def book_delete():
    global root2
    root2 = tk.Tk()
    root2.title("下架图书")
    v1 = tk.StringVar()
    global input4
    labe1 = tk.Label(root2, text="请输入要下架的图书名:", font=36).grid(row=0, column=0)
    input4 = tk.Entry(root2, textvariable=v1)
    input4.grid(row=1, column=0)
    tk.Button(root2, text='确认', width=10,font='宋体', command=delete_end).grid(row=2, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消', width=10, font='宋体',command=exit_login3).grid(row=2, column=1, sticky=tk.E, padx=10, pady=5)

def donate_end():
    db = pymysql.connect(host="localhost", user="root", password="123456", db="library")
    cursor = db.cursor()
    name = input10.get()
    amount = input11.get()
    write = input12.get()
    tim = input13.get()
    sql = "SELECT num FROM book WHERe bname='%s'" % (name)
    cursor.execute(sql)
    results = cursor.fetchone()
    if results:
        sql = "UPDATe book SET num=num+%s WHERe bname='%s'" % (amount, name)
        try:
            cursor.execute(sql)
            db.commit()
            msg._show(title="成功", message="新进图书更新成功")
        except:
            msg._show(title="系统故障", message="新进图书更新失败")
            db.rollback()
    else:
        sql = "INSERT INTO book(writer,num,bname,ptime) VALUES ('%s',%s,'%s','%s')" % (write, amount, name, tim)
        try:
            cursor.execute(sql)
            db.commit()
            msg._show(title="成功", message="新进图书更新成功")
        except:
            msg._show(title="错误", message="输入信息有误")
            db.rollback()
    db.close()

def borrow_select():
    global root2
    root2 = tk.Tk()
    root2.title("查询借阅记录")
    v1 = tk.StringVar()
    global input5
    labe1 = tk.Label(root2, text="请输入要查询的读者学号:", font=36).grid(row=0, column=0)
    input5 = tk.Entry(root2, textvariable=v1)
    input5.grid(row=1, column=0)
    tk.Button(root2, text='确认', width=10,font='宋体', command=borrow_end).grid(row=2, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消', width=10, font='宋体',command=exit_login3).grid(row=2, column=1, sticky=tk.E, padx=10, pady=5)


def book_select():
    v1=tk.StringVar()
    global root2
    root2=tk.Tk()
    root2.title("查询图书")
    global input_book
    labe1 = tk.Label(root2, text="请输入您要查询的图书名:", font=36).grid(row=0, column=0)
    input_book = tk.Entry(root2,textvariable=v1)
    input_book.grid(row=0,column=1)
    tk.Button(root2, text='确认', width=10,fg='green', command=check_book).grid(row=1, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消', width=10, fg='red',command=exit_login3).grid(row=1, column=1, sticky=tk.E, padx=10, pady=5)

def book_in():
    global root2
    root2 = tk.Tk()
    root2.title("新进图书")
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    global input10,input11,input12,input13
    labe1 = tk.Label(root2, text="请输入您要新进的图书名:", font=36).grid(row=0, column=0)
    labe12 = tk.Label(root2, text="请输入您要新进的图书的数量:", font=36).grid(row=1, column=0)
    labe13 = tk.Label(root2, text="请输入您要新进的作者:", font=36).grid(row=2, column=0)
    labe4 = tk.Label(root2, text="请输入您要新进的图书的出版时间:", font=36).grid(row=3, column=0)
    input10 = tk.Entry(root2, textvariable=v1)
    input10.grid(row=0, column=1)
    input11 = tk.Entry(root2, textvariable=v2)
    input11.grid(row=1, column=1)
    input12 = tk.Entry(root2, textvariable=v3)
    input12.grid(row=2, column=1)
    input13 = tk.Entry(root2, textvariable=v4)
    input13.grid(row=3, column=1)
    tk.Button(root2, text='确认', width=10, fg='green',font='宋体',command=donate_end).grid(row=4, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消', width=10,fg='red', font='宋体',command=exit_login3).grid(row=4, column=1, sticky=tk.E, padx=10, pady=5)


def success_tip(id):
    global root1
    root.destroy()
    root2.destroy()
    root1 = tk.Tk()
    root1.title('科B311图书管理系统')
    #root1.geometry("280x250")
    labe1 = tk.Label(root1, text="欢迎来到科B311图书管理系统,请选择您要进行的操作:", font=36).grid(row=0, column=0)
    tk.Button(root1, text='打印缺书单',bg='cyan',fg='black', font='宋体',width=50,height=2, command=book_print).grid(row=1, column=0)
    tk.Button(root1, text='下架图书',bg='violet',fg='black', font='宋体',width=50,height=2,  command=book_delete).grid(row=5, column=0)
    tk.Button(root1, text='查询借阅记录', bg='yellow',fg='black',font='宋体',width=50,height=2, command=borrow_select).grid(row=3, column=0)
    tk.Button(root1, text='新进图书', bg='sky blue',fg='black',font='宋体',width=50,height=2,  command=book_in).grid(row=4, column=0)
    tk.Button(root1, text='查询图书信息', bg='pink',fg='black',font='宋体',width=50,height=2, command=book_select).grid(row=2, column=0)
    tk.Button(root1, text='退出', bg='red',fg='black',font='宋体',width=50,height=2, command=exit_loginx).grid(row=6, column=0)

def exit_loginx():
    root1.destroy()
    frame()

def exit_login2():
    root1.destroy()

def login_check():
    db = pymysql.connect(host="localhost", user="root", password="123456", db="library")
    cursor = db.cursor()
    id=input_id.get()
    name=input2.get()
    sql = "SELECT mpassward FROM mpass WHERe mid='%s'" % (id)
    cursor.execute(sql)
    results = cursor.fetchone()
    if results:
            if name == results[0]:
                success_tip(id)
            else:
               msg._show(title='错误!',message='账号密码输入错误!')
    else:
        msg._show(title='错误!',message='您输入的用户不存在!')
    db.close()

def auto_login():
    global root2
    root2 = tk.Tk()
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    root2.title("登入")
    labe1=tk.Label(root2,text="职工号:",font=36).grid(row=0, column=0)
    label2=tk.Label(root2,text="密码:",font=36).grid(row=1,column=0)
    global input_id,input2
    input_id = tk.Entry(root2, textvariable=v1)
    input_id.grid(row=0, column=1, padx=10, pady=5)
    input2 = tk.Entry(root2, textvariable=v2, show='*')
    input2.grid(row=1, column=1, padx=10, pady=5)
    tk.Button(root2, text='登录', width=10,font='宋体', fg='green',command=login_check).grid(row=3, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='退出', width=10, font='宋体',fg='red',command=exit_login3).grid(row=3, column=1, sticky=tk.E, padx=10, pady=5)

def exit_login():
    root.destroy()
    user.frame()

def exit_login3():
    root2.destroy()

def resiger():
    root2 = tk.Tk()
    root2.title("注册")
    label1  = tk.Label(root2, text="职工号:", font=36).grid(row=0,column=0)
    label2 = tk.Label(root2, text="密码:", font=36).grid(row=1,column=0)
    label3 = tk.Label(root2,text="性别:",font=36).grid(row=2,column=0)
    label4 = tk.Label(root2,text="所属学院:",font=36).grid(row=3,column=0)
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    global input1,input2,input3,input4
    input1 = tk.Entry(root2, textvariable=v1)
    input1.grid(row=0, column=1, padx=10, pady=5)
    input2 = tk.Entry(root2, textvariable=v2, show='*')
    input2.grid(row=1, column=1, padx=10, pady=5)
    input3 = tk.Entry(root2, textvariable=v3)
    input3.grid(row=2, column=1, padx=10, pady=5)
    input4 = tk.Entry(root2, textvariable=v4,)
    input4.grid(row=3, column=1, padx=10, pady=5)
    tk.Button(root2, text='确认', fg='green',width=10, command=resiger_end).grid(row=4, column=0, sticky=tk.W, padx=10, pady=5)

def frame():
    global root
    root = tk.Tk()
    root.title('科B311图书管理系统登录')
    root.geometry("430x750")
    photo = tk.PhotoImage(file=BACK_PATH)
    theLabel = tk.Label(root, image=photo, compound='bottom', fg="white").grid(row=3, column=0)
    tk.Button(root, text='登入',bg='yellow',fg='green', width=62,height=9, command=auto_login).grid(row=0, column=0)
    tk.Button(root, text='注册',bg='pink',fg='orange' ,width=62, height=9, command=resiger).grid(row=1, column=0)
    tk.Button(root, text='退出',bg='cyan',fg='red',width=62,height=9,command=exit_login).grid(row=2, column=0)
    root.mainloop()

if __name__ == '__main__':
    frame()

再者是用户登录界面user.py

import tkinter as tk
import tkinter.messagebox as msg
import pymysql
import os
from PIL import Image,ImageTk



def check_book():
    db = pymysql.connect(host="localhost",user= "root",passwd= "123456", database="library")
    cursor = db.cursor()
    a = input_book.get()
    sql = "SELECt * FROM book WHERe bname = '%s'" % (a)
    cursor.execute(sql)
    results = cursor.fetchone()
    print(results)
    if results:
        root3 = tk.Tk()
        root3.title('查询到的书')
        val = "您要查询的书号为:%s" % (results[0])
        print1 = tk.Label(root3, text=val)
        print1.grid(row=0, column=0, padx=10, pady=5)
        val = "您要查询的书的作者为:%s" % (results[1])
        print3 = tk.Label(root3, text=val)
        print3.grid(row=2, column=0, padx=10, pady=5)
        val = "您要查询的书名为:%s" % (results[3])
        print5 = tk.Label(root3, text=val)
        print5.grid(row=4, column=0, padx=10, pady=5)
        val = "您要查询的书的出版日期为:%s" % (results[4])
        print6 = tk.Label(root3, text=val)
        print6.grid(row=5, column=0, padx=10, pady=5)
    else:
        msg._show(title='错误', message='没有查到您要查询的记录')
    db.close()

def borrow_end():
    db = pymysql.connect(host="localhost", user="root",passwd= "123456",database= "library")
    cursor = db.cursor()
    id = input_id.get()
    name = input8.get()
    sql = "SELECt bid,num FROM book WHERe bname='%s'" % (name)
    cursor.execute(sql)
    results = cursor.fetchone()
    print(results)
    if results[1] > 0:
        sql = "INSERT INTO borrow(rid,bid,btime) VALUES(%s,%s,CURDATE())" % (id, results[0])

        try:
            cursor.execute(sql)
            db.commit()
            msg._show(title="成功",message="借阅成功!")
        except:
            msg._show(title="系统故障",message="借阅失败!")
    else:
        msg._show(title="库存量不足",message="对不起,您要借阅的图书库存不足!")
    db.close()

def return_end():
    db = pymysql.connect(host="localhost", user="root",passwd= "123456", database="library")
    cursor = db.cursor()
    id = input_id.get()
    name = input9.get()
    sql = "SELECt bid FROM book WHERe bname = '%s'" % (name)
    cursor.execute(sql)
    results = cursor.fetchone()
    sql = "SELECt lid FROM borrow WHERe bid=%s AND rid=%s" % (results[0], id)
    cursor.execute(sql)
    result = cursor.fetchone()
    sql = "UPDATe borrow SET rtime=CURDATE()WHERe lid= %s"%(result[0])
    try:
        cursor.execute(sql)
        db.commit()
        msg._show(title='成功',message='还书成功')
    except:
        msg._show(title='系统故障',message='还失败')
    db.close()

def donate_end():
    db = pymysql.connect(host="localhost",user= "root", passwd="123456", database="library")
    cursor = db.cursor()
    id = input_id.get()
    name = input10.get()
    amount = input11.get()
    write = input12.get()
    tim= input13.get()
    sql = "SELECT num FROM book WHERe bname='%s'" % (name)
    cursor.execute(sql)
    results = cursor.fetchone()
    if results:
        sql = "UPDATe book SET num=num+%s WHERe bname='%s'" % (amount, name)
        try:
            cursor.execute(sql)
            db.commit()
            msg._show(title="成功",message="捐书成功!谢谢您")
        except:
            msg._show(title="系统故障",message="捐书失败")
            db.rollback()
    else:
        sql = "SELECT MAX(bid) FROM book"
        cursor.execute(sql)
        results = cursor.fetchone()
        result=list(results)
        result[0] = result[0] + 1
        results=tuple(result)
        sql = "INSERT INTO book VALUES (%s,'%s',%s,'%s','%s')" % (results[0], write, amount, name, tim)
        try:
            cursor.execute(sql)
            db.commit()
            msg._show(title="成功", message="捐书成功!谢谢您")
        except:
            msg._show(title="错误", message="输入信息有误")
            db.rollback()
    db.close()

def book_select():
    v1=tk.StringVar()
    global root2
    root2=tk.Tk()
    root2.title("查询图书")
    global input_book
    labe1 = tk.Label(root2, text="请输入您要查询的图书名:", font=36).grid(row=0, column=0)
    input_book = tk.Entry(root2,textvariable=v1)
    input_book.grid(row=0,column=1)
    tk.Button(root2, text='确认', width=10, command=check_book).grid(row=1, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=1, column=1, sticky=tk.E, padx=10, pady=5)

def book_borrow():
    db = pymysql.connect(host="localhost",user= "root",passwd= "123456",database= "library")
    cursor = db.cursor()
    id=input_id.get()
    sql = "SELECT bleft FROM reader WHERe rid = %s" % (id)
    cursor.execute(sql)
    result = cursor.fetchone()
    v_borrow=tk.StringVar()
    if result[0] == 0:
        msg._show(title="错误",message="你已达最大借阅量,借阅失败")
    global root2
    root2 = tk.Tk()
    root2 .title("借阅")
    global input8
    labe1 = tk.Label(root2, text="请输入您要借阅的图书名:", font=36).grid(row=0, column=0)
    input8 = tk.Entry(root2, textvariable=v_borrow)
    input8.grid(row=1,column=0)
    tk.Button(root2, text='确认', width=10, command=borrow_end).grid(row=2, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=2, column=1, sticky=tk.E, padx=10, pady=5)
    db.close()

def return_book():
    global root2
    root2 = tk.Tk()
    root2.title("还书")
    v1=tk.StringVar()
    global input9
    labe1 = tk.Label(root2, text="请输入您要还的图书名:", font=36).grid(row=0, column=0)
    input9 = tk.Entry(root2, textvariable=v1)
    input9.grid(row=1, column=0)
    tk.Button(root2, text='确认', width=10, command=return_end).grid(row=2, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消',fg='red' ,width=10, command=exit_login3).grid(row=2, column=1, sticky=tk.E, padx=10, pady=5)

def donate_book():
    global root2
    root2 = tk.Tk()
    root2.title("捐书")
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    global input10,input11,input12,input13
    labe1 = tk.Label(root2, text="请输入您要捐赠的图书名:", font=36).grid(row=0, column=0)
    labe12 = tk.Label(root2, text="请输入您要捐赠的图书的数量:", font=36).grid(row=1, column=0)
    labe13 = tk.Label(root2, text="请输入您要捐赠的作者:", font=36).grid(row=2, column=0)
    labe4 = tk.Label(root2, text="请输入您要捐赠的图书的出版时间:", font=36).grid(row=3, column=0)
    input10 = tk.Entry(root2, textvariable=v1)
    input10.grid(row=0, column=1)
    input11 = tk.Entry(root2, textvariable=v2)
    input11.grid(row=1, column=1)
    input12 = tk.Entry(root2, textvariable=v3)
    input12.grid(row=2, column=1)
    input13 = tk.Entry(root2, textvariable=v4)
    input13.grid(row=3, column=1)
    tk.Button(root2, text='确认', fg='green',width=10, command=donate_end).grid(row=4, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消',fg='red' ,width=10, command=exit_login3).grid(row=4, column=1, sticky=tk.E, padx=10, pady=5)

def library_mess():
    db = pymysql.connect(host="localhost", user="root", passwd="123456", database="library")
    cursor = db.cursor()
    sql = "SELECt * FROM lib_mess "
    cursor.execute(sql)
    results = cursor.fetchone()
    root4=tk.Tk()
    root4.title("图书馆信息")
    val = "图书馆名字:%s" % (results[0])
    print1 = tk.Label(root4, text=val)
    print1.grid(row=0, column=0, padx=10, pady=5)
    val = "地址为:%s" % (results[1])
    print2 = tk.Label(root4, text=val)
    print2.grid(row=1, column=0, padx=10, pady=5)
    db.close()

def success_tip(id):
    root1 = tk.Tk()
    root1.title('科B311图书管理系统')
    labe1 = tk.Label(root1, text="欢迎来到科B311图书管理系统,请选择您要进行的操作:", font=36).grid(row=0, column=0)
    tk.Button(root1, text='查询图书',bg='cyan',fg='black',  command=book_select).grid(row=1, column=0)
    tk.Button(root1, text='借阅图书',bg='violet',fg='black',  command=book_borrow).grid(row=2, column=0)
    tk.Button(root1, text='归还图书',bg='yellow',fg='black', command=return_book).grid(row=3,  column=0)
    tk.Button(root1, text='捐赠图书',bg='pink',fg='black',command=donate_book).grid(row=4, column=0)
    tk.Button(root1, text='图书馆信息', bg='green', fg='black', command=library_mess).grid(row=5, column=0)
    tk.Button(root1, text='退出',bg='red',fg='black', command=resiger).grid(row=6, column=0)
    root1.mainloop()
def exit_login2():
    root1.destroy()

def login_check():
    db = pymysql.connect(host="localhost",user= "root",passwd= "123456", database="library")
    cursor = db.cursor()
    id=input_id.get()
    name=input2.get()
    sql = "SELECT rname FROM reader WHERe rid='%s'" % (id)
    cursor.execute(sql)
    results = cursor.fetchone()
    if results:
            if name == results[0]:
                success_tip(id)
            else:
               msg._show(title='错误!',message='账号密码输入错误!')
    else:
        msg._show(title='错误!',message='您输入的用户不存在!')
    db.close()

def auto_login():
    global root1
    root1 = tk.Tk()
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    root1.title("登入")
    labe1=tk.Label(root1,text="学号:",font=36).grid(row=0, column=0)
    label2=tk.Label(root1,text="密码:",font=36).grid(row=1,column=0)
    global input_id,input2
    input_id = tk.Entry(root1, textvariable=v1)
    input_id.grid(row=0, column=1, padx=10, pady=5)
    input2 = tk.Entry(root1, textvariable=v2, show='*')
    input2.grid(row=1, column=1, padx=10, pady=5)
    tk.Button(root1, text='登录', fg='green',width=10, command=login_check).grid(row=3, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root1, text='退出', fg='red',width=10, command=exit_login2).grid(row=3, column=1, sticky=tk.E, padx=10, pady=5)

def exit_login():
    root.destroy()


def resiger_end():
    db = pymysql.connect(host="localhost", user="root",passwd= "123456", database="library")
    cursor = db.cursor()
    rid = input1.get()
    name = input2.get()
    xue = input3.get()
    pw = input4.get()
    sex = input5.get()
    clas = input6.get()
    sql = "INSERT INTO reader VALUES(%s,'%s','%s','%s',10)" % (rid, pw, sex, clas)
    sql1 ="INSERT INTO reader_mess VALUES(%s,'%s','%s','%s','%s',10)" % (rid,name,sex,xue,clas)
    try:
        cursor.execute(sql)
        db.commit()
        cursor.execute(sql1)
        db.commit()
        msg._show(title='成功', message='注册成功!')
    except:
        msg._show(title='错误', message='注册失败!')
    db.close()

def resiger():
    root2 = tk.Tk()
    root2.title("注册")
    label1  = tk.Label(root2, text="学号:", font=36).grid(row=0,column=0)
    label2 = tk.Label(root2, text="密码:", font=36).grid(row=3,column=0)
    label3 = tk.Label(root2,text="性别:",font=36).grid(row=4,column=0)
    label4 = tk.Label(root2,text="班级:",font=36).grid(row=5,column=0)
    label5 = tk.Label(root2, text="姓名:", font=36).grid(row=1, column=0)
    label6 = tk.Label(root2, text="学院:", font=36).grid(row=2, column=0)
    v1 = tk.StringVar()
    v2 = tk.StringVar()
    v3 = tk.StringVar()
    v4 = tk.StringVar()
    v5 = tk .StringVar()
    v6 = tk .StringVar()
    global input1,input2,input3,input4,input5,input6
    input1 = tk.Entry(root2, textvariable=v1)
    input1.grid(row=0, column=1, padx=10, pady=5)
    input2 = tk.Entry(root2, textvariable=v2)
    input2.grid(row=1, column=1, padx=10, pady=5)
    input3 = tk.Entry(root2, textvariable=v3)
    input3.grid(row=2, column=1, padx=10, pady=5)
    input4 = tk.Entry(root2, textvariable=v4,show="*")
    input4.grid(row=3, column=1, padx=10, pady=5)
    input5 = tk.Entry(root2, textvariable=v5, )
    input5.grid(row=4, column=1, padx=10, pady=5)
    input6 = tk.Entry(root2, textvariable=v6, )
    input6.grid(row=5, column=1, padx=10, pady=5)
    tk.Button(root2, text='确认', width=10, command=resiger_end).grid(row=6, column=0, sticky=tk.W, padx=10, pady=5)
def exit_login3():
    root2.destroy()

def frame():
    global root
    root = tk.Tk()
    root.title('科B311图书管理系统登录')
    root.geometry("600x580")
    tk.Button(root, text='登入', bg= 'pink',fg='green',width=70,font=('宋体',15),height=9, command=auto_login).grid(row=1, column=0)
    tk.Button(root, text='注册', bg='yellow',fg='blue',width=70,font=('宋体',15),height=9, command=resiger).grid(row=2, column=0)
    tk.Button(root, text='退出',bg='cyan',fg='orange',width=70,font=('宋体',15),height=9,command=exit_login).grid(row=3, column=0)
    root.mainloop()


if __name__ == '__main__':
    frame()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/954066.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号