Library Management System
Library Management System
Management
System
INDEX
PREFACE
INTRODUCTION
OBJECTIVE
SCOPE
EXISTING SYSTEM AND DEMERITS
PROPOSED SYSTEM (MERITS)
INPUT & OUTPUT
SYSTEM REQUIREMENTS
CONCLUSION
BIBLIOGRAPHY
SOURCE CODE
OUTPUT
PREFACE
Tkinter:
Tkinter is a Python binding to the Tk GUI toolkit. It is the
standard Python interface to the Tk GUI toolkit, and is Python's
de facto standard GUI. Tkinter is included with standard Linux,
Microsoft Windows and macOS installs of Python. The name
Tkinter comes from the Tk interface.
Tkinter was written by Steen Lumholt and Guido van Rossum,
then later revised by Fredrik Lundh. Tkinter is free software
released under a Python license.
PIL (Pillow)
Python Imaging Library is a free and open-source additional
library for the Python programming language that adds support
for opening, manipulating, and saving many different image file
formats. It is available for Windows, Mac OS X and Linux. The
latest version of PIL is 1.1.7, was released in September 2009
and supports Python 1.5.2–2.7. Development of the original
project, known as PIL, was discontinued in 2011.
PyMySQL:
PyMySQL is a pure-Python MySQL client library, which means
it is a Python package that creates an API interface for us to
access MySQL relational databases.
Prerequisites
use library;
1. books
2. books_issued
Project Code
Let’s start the detailed discussion of each and every file of our library
management system python project:
1. main.py
1.1. Importing the Modules
Code:
from tkinter import *
import pymysql
Code:
mypass = "tiger"
mydatabase="library"
con = pymysql.connect(host="localhost",user="root",
password=mypass,database=mydatabase)
Code:
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
Output:
1.4. Adding a Background Image
Code:
same=True
n=0.25
background_image =Image.open("lib.jpg")
newImageSizeWidth = int(imageSizeWidth*n)
if same:
newImageSizeHeight = int(imageSizeHeight*n)
else:
newImageSizeHeight = int(imageSizeHeight/n)
background_image =
background_image.resize((newImageSizeWidth,newImageSizeHeigh
t),Image.LANCZOS)
img = ImageTk.PhotoImage(background_image)
Canvas1 = Canvas(root)
Canvas1.create_image(300,340,image = img)
Canvas1.config(bg="white",width = newImageSizeWidth, height
= newImageSizeHeight)
Canvas1.pack(expand=True,fill=BOTH)
Code:
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.6,relheight
=0.16)
Code:
btn1 = Button(root,text="Add Book Details",bg='black',
fg='white', command=addBook)
btn1.place(relx=0.28,rely=0.4, relwidth=0.45,relheight=0.1)
btn2.place(relx=0.28,rely=0.5, relwidth=0.45,relheight=0.1)
btn3 = Button(root,text="View Book List",bg='black',
fg='white', command=View)
btn3.place(relx=0.28,rely=0.6, relwidth=0.45,relheight=0.1)
btn4.place(relx=0.28,rely=0.7, relwidth=0.45,relheight=0.1)
btn5.place(relx=0.28,rely=0.8, relwidth=0.45,relheight=0.1)
root.mainloop()
Output:
2. AddBook.py
Code:
from tkinter import *
import pymysql
2.2. Function – bookRegister()
Code:
def bookRegister():
bid = bookInfo1.get()
title = bookInfo2.get()
author = bookInfo3.get()
global status
if CheckVar.get()==0:
status = "Available"
elif CheckVar.get()==1:
status = "Issued"
try:
cur.execute(insertBooks)
con.commit()
messagebox.showinfo('Success',"Book added
successfully")
except:
print(bid)
print(title)
print(author)
print(status)
root.destroy()
Code:
def addBook():
class GUI:
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
mypass = "tiger"
mydatabase="library"
cur = con.cursor()
# Book Table
bookTable = "books"
Canvas1 = Canvas(root)
Canvas1.config(bg="#ff6e40")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheigh
t=0.13)
headingLabel.place(relx=0,rely=0, relwidth=1,
relheight=1)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.
4)
# Book ID
lb1.place(relx=0.05,rely=0.2, relheight=0.08)
bookInfo1 = Entry(labelFrame)
bookInfo1.place(relx=0.3,rely=0.2, relwidth=0.62,
relheight=0.08)
# Title
lb2 = Label(labelFrame,text="Title : ", bg='black',
fg='white')
lb2.place(relx=0.05,rely=0.35, relheight=0.08)
bookInfo2 = Entry(labelFrame)
bookInfo2.place(relx=0.3,rely=0.35, relwidth=0.62,
relheight=0.08)
# Book Author
lb3.place(relx=0.05,rely=0.50, relheight=0.08)
bookInfo3 = Entry(labelFrame)
bookInfo3.place(relx=0.3,rely=0.50, relwidth=0.62,
relheight=0.08)
# Book Status
global CheckVar
CheckVar = IntVar()
avail = Radiobutton(labelFrame,text="Available",
variable = CheckVar, value = 0 )
avail.place(relx=0.4,rely=0.65, relheight=0.08)
avail.invoke()
issue = Radiobutton(labelFrame,text="Issued",
variable = CheckVar, value = 1 )
issue.place(relx=0.675,rely=0.65, relheight=0.08)
#Submit Button
SubmitBtn = Button(root,text="SUBMIT",bg='#d1ccc0',
fg='black',command=bookRegister)
SubmitBtn.place(relx=0.28,rely=0.9,
relwidth=0.18,relheight=0.08)
quitBtn = Button(root,text="Quit",bg='#f7f1e3',
fg='black', command=root.destroy)
quitBtn.place(relx=0.53,rely=0.9,
relwidth=0.18,relheight=0.08)
root.mainloop()
Variables
Buttons
3. ViewBooks.py
3.1. Importing the necessary modules
Code:
from tkinter import *
import pymysql
3.2. Connection to MySql server
Code:
mypass = "tiger"
mydatabase="library"
con = pymysql.connect(host="localhost",user="root",
password=mypass,database=mydatabase)
bookTable = "books"
Code:
def View():
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
Canvas1 = Canvas(root)
Canvas1.config(bg="#12a4d9")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheigh
t=0.13)
headingLabel.place(relx=0,rely=0, relwidth=1,
relheight=1)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.
5)
y = 0.25
Label(labelFrame, text="%-10s%-40s%-30s%-20s"%
('BID','Title','Author','Status'),
bg='black',fg='white').place(relx=0.07,rely=0.1)
Label(labelFrame, text =
"-----------------------------------------------------------
-----------------",bg='black',fg='white').place
(relx=0.05,rely=0.2)
try:
cur.execute(getBooks)
con.commit()
for i in cur:
Label(labelFrame,text="%-10s%-30s%-30s%-20s"%
(i[0],i[1],i[2],i[3]) ,bg='black',
fg='white').place(relx=0.07,rely=y)
y += 0.1
except:
quitBtn = Button(root,text="Quit",bg='#f7f1e3',
fg='black', command=root.destroy)
quitBtn.place(relx=0.4,rely=0.9,
relwidth=0.18,relheight=0.08)
root.mainloop()
4. DeleteBook.py
Code:
from tkinter import *
import pymysql
4.2. Connect to MySql Server
Code:
mypass = "tiger"
mydatabase="library"
con = pymysql.connect(host="localhost",user="root",
password=mypass,database=mydatabase)
issueTable = "books_issued"
Code:
def deleteBook():
bid = bookInfo1.get()
cur.execute(deleteSql)
con.commit()
cur.execute(deleteIssue)
con.commit()
except:
print(bid)
bookInfo1.delete(0, END)
root.destroy()
Code:
def delete():
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
Canvas1 = Canvas(root)
Canvas1.config(bg="#006B38")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheigh
t=0.13)
headingLabel.place(relx=0,rely=0, relwidth=1,
relheight=1)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.
5)
# Book ID to Delete
lb2.place(relx=0.05,rely=0.5)
bookInfo1 = Entry(labelFrame)
bookInfo1.place(relx=0.3,rely=0.5, relwidth=0.62)
#Submit Button
SubmitBtn = Button(root,text="SUBMIT",bg='#d1ccc0',
fg='black',command=deleteBook)
SubmitBtn.place(relx=0.28,rely=0.9,
relwidth=0.18,relheight=0.08)
quitBtn = Button(root,text="Quit",bg='#f7f1e3',
fg='black', command=root.destroy)
quitBtn.place(relx=0.53,rely=0.9,
relwidth=0.18,relheight=0.08)
root.mainloop()
5. IssueBook.py
Code:
from tkinter import *
import pymysql
5.2. Connecting to the MySql server
Code:
mypass = "tiger"
mydatabase="library"
con = pymysql.connect(host="localhost",user="root",
password=mypass,database=mydatabase)
issueTable = "books_issued"
bookTable = "books"
Code:
def issue():
global
issueBtn,labelFrame,lb1,inf1,inf2,quitBtn,root,Canvas1,statu
s
bid = inf1.get()
issueto = inf2.get()
issueBtn.destroy()
labelFrame.destroy()
lb1.destroy()
inf1.destroy()
inf2.destroy()
try:
cur.execute(extractBid)
con.commit()
for i in cur:
allBid.append(i[0])
if bid in allBid:
cur.execute(checkAvail)
con.commit()
for i in cur:
check = i[0]
if check == 'Available':
status = True
else:
status = False
else:
messagebox.showinfo("Error","Book ID not
present")
except:
try:
if bid in allBid and status == True:
cur.execute(issueSql)
con.commit()
cur.execute(updateStatus)
con.commit()
messagebox.showinfo('Success',"Book Issued
Successfully")
root.destroy()
else:
allBid.clear()
messagebox.showinfo('Message',"Book Already
Issued")
root.destroy()
return
except:
print(bid)
print(issueto)
allBid.clear()
Code:
def issueBook():
global
issueBtn,labelFrame,lb1,inf1,inf2,quitBtn,root,Canvas1,statu
s
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
Canvas1 = Canvas(root)
Canvas1.config(bg="#D6ED17")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheigh
t=0.13)
headingLabel = Label(headingFrame1, text="Issue Book",
bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1,
relheight=1)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.
5)
# Book ID
lb1.place(relx=0.05,rely=0.2)
inf1 = Entry(labelFrame)
inf1.place(relx=0.3,rely=0.2, relwidth=0.62)
inf2 = Entry(labelFrame)
inf2.place(relx=0.3,rely=0.4, relwidth=0.62)
#Issue Button
issueBtn = Button(root,text="Issue",bg='#d1ccc0',
fg='black',command=issue)
issueBtn.place(relx=0.28,rely=0.9,
relwidth=0.18,relheight=0.08)
quitBtn = Button(root,text="Quit",bg='#aaa69d',
fg='black', command=root.destroy)
quitBtn.place(relx=0.53,rely=0.9,
relwidth=0.18,relheight=0.08)
root.mainloop()
6. ReturnBook.py
Code:
from tkinter import *
import pymysql
6.2. Connecting to the MySql server
Code:
mypass = "tiger"
mydatabase="library"
con = pymysql.connect(host="localhost",user="root",
password=mypass,database=mydatabase)
issueTable = "books_issued"
bookTable = "books"
Code:
def returnn():
bid = bookInfo1.get()
cur.execute(extractBid)
con.commit()
for i in cur:
allBid.append(i[0])
if bid in allBid:
cur.execute(checkAvail)
con.commit()
for i in cur:
check = i[0]
if check == 'Issued':
status = True
else:
status = False
else:
messagebox.showinfo("Error","Book ID not
present")
except:
print(bid in allBid)
print(status)
try:
cur.execute(issueSql)
con.commit()
cur.execute(updateStatus)
con.commit()
messagebox.showinfo('Success',"Book Returned
Successfully")
else:
allBid.clear()
root.destroy()
return
except:
allBid.clear()
root.destroy()
Code:
def returnBook():
global
bookInfo1,SubmitBtn,quitBtn,Canvas1,con,cur,root,labelFrame,
lb1
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
Canvas1 = Canvas(root)
Canvas1.config(bg="#006B38")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheigh
t=0.13)
headingLabel.place(relx=0,rely=0, relwidth=1,
relheight=1)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.
5)
# Book ID to Delete
lb1.place(relx=0.05,rely=0.5)
bookInfo1 = Entry(labelFrame)
bookInfo1.place(relx=0.3,rely=0.5, relwidth=0.62)
#Submit Button
SubmitBtn = Button(root,text="Return",bg='#d1ccc0',
fg='black',command=returnn)
SubmitBtn.place(relx=0.28,rely=0.9,
relwidth=0.18,relheight=0.08)
quitBtn = Button(root,text="Quit",bg='#f7f1e3',
fg='black', command=root.destroy)
quitBtn.place(relx=0.53,rely=0.9,
relwidth=0.18,relheight=0.08)
root.mainloop()
OUTPUT
CONCLUSION
●
https://projectsgeek.com/2017/03/digital-library-system-
project.html