当前位置:   article > 正文

python+mysql设计简单GUI的图书管理系统_python+mysql做gui系统管理

python+mysql做gui系统管理

图书管理系统:界面设计的比较丑请忽略
数据要求
根据系统的需求,将需要的数据分类记录如下:
(1) 图书信息:编号、名称、储量、作者、出版时间
(2) 图书借阅信息:读者学号、图书编号、记录编号、借书日期、还书日期
(3) 读者信息:学号、姓名、性别、班级、剩余最大借书量
(4) 管理者信息:管理者姓名、职工号、权限级别

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

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

BACK_PATH="resources"+os.sep+"background.gif"


def check_book():
    db = pymysql.connect("localhost", "root", "*****", "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])
        print1 = tk.Label(root3, text=val)
        print1.grid(row=0, column=0, padx=10, pady=5)
        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 borrow_end():
    db = pymysql.connect("localhost", "root", "*****", "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()
    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("localhost", "root", "*****", "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("localhost", "root", "*****", "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()
        results[0] = results[0] + 1
        sql = "INSERT INTO book VALUES (%s,'%s',%s,'%s','%s')" % (results, 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("localhost", "root", "*****", "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='取消', 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='确认', width=10, command=donate_end).grid(row=4, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=4, column=1, sticky=tk.E, padx=10, pady=5)


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

def login_check():
    db = pymysql.connect("localhost", "root", "*****", "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='登录', width=10, command=login_check).grid(row=3, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root1, text='退出', width=10, command=exit_login2).grid(row=3, column=1, sticky=tk.E, padx=10, pady=5)

def exit_login():
    root.destroy()

def exit_login3():
    root2.destroy()

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

def resiger():
    root2 = tk.Tk()
    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)
    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='确认', width=10, command=resiger_end).grid(row=4, column=0, sticky=tk.W, padx=10, pady=5)
    tk.Button(root2, text='取消', width=10, command=exit_login3).grid(row=4, column=1, sticky=tk.E, padx=10, pady=5)

def frame():
    global root
    root = tk.Tk()
    root.title('YTU图书管理系统登录')
    root.geometry("500x500")
    #photo=tk.PhotoImage(file=BACK_PATH)
    #theLabel = tk.Label(root,image = photo,compound = tk.CENTER,fg = "white").pack(fill="both",expand=1)
    tk.Button(root, text='登入', width=70,height=9, command=auto_login).grid(row=0, column=0,)
    tk.Button(root, text='注册', width=70,height=9, command=resiger).grid(row=1, column=0)
    tk.Button(root, text='退出',width=70,height=9,command=exit_login).grid(row=2, column=0)
    root.mainloop()


if __name__ == '__main__':
    frame()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/726996
推荐阅读
相关标签
  

闽ICP备14008679号