Skip to content

Commit 8d09a1d

Browse files
committed
✨ Library Management System
1 parent ef84882 commit 8d09a1d

File tree

8 files changed

+539
-0
lines changed

8 files changed

+539
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from tkinter import *
2+
from PIL import ImageTk,Image
3+
from tkinter import messagebox
4+
import pymysql
5+
6+
def bookRegister():
7+
8+
bid = bookInfo1.get()
9+
title = bookInfo2.get()
10+
author = bookInfo3.get()
11+
status = bookInfo4.get()
12+
status = status.lower()
13+
14+
insertBooks = "insert into "+bookTable+" values('"+bid+"','"+title+"','"+author+"','"+status+"')"
15+
try:
16+
cur.execute(insertBooks)
17+
con.commit()
18+
messagebox.showinfo('Success',"Book added successfully")
19+
except:
20+
messagebox.showinfo("Error","Can't add data into Database")
21+
22+
print(bid)
23+
print(title)
24+
print(author)
25+
print(status)
26+
27+
28+
root.destroy()
29+
30+
def addBook():
31+
32+
global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,root
33+
34+
root = Tk()
35+
root.title("Library")
36+
root.minsize(width=400,height=400)
37+
root.geometry("600x500")
38+
39+
# Add your own database name and password here to reflect in the code
40+
mypass = "root"
41+
mydatabase="db"
42+
43+
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
44+
cur = con.cursor()
45+
46+
# Enter Table Names here
47+
bookTable = "books" # Book Table
48+
49+
Canvas1 = Canvas(root)
50+
51+
Canvas1.config(bg="#ff6e40")
52+
Canvas1.pack(expand=True,fill=BOTH)
53+
54+
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
55+
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
56+
57+
headingLabel = Label(headingFrame1, text="Add Books", bg='black', fg='white', font=('Courier',15))
58+
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
59+
60+
61+
labelFrame = Frame(root,bg='black')
62+
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4)
63+
64+
# Book ID
65+
lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
66+
lb1.place(relx=0.05,rely=0.2, relheight=0.08)
67+
68+
bookInfo1 = Entry(labelFrame)
69+
bookInfo1.place(relx=0.3,rely=0.2, relwidth=0.62, relheight=0.08)
70+
71+
# Title
72+
lb2 = Label(labelFrame,text="Title : ", bg='black', fg='white')
73+
lb2.place(relx=0.05,rely=0.35, relheight=0.08)
74+
75+
bookInfo2 = Entry(labelFrame)
76+
bookInfo2.place(relx=0.3,rely=0.35, relwidth=0.62, relheight=0.08)
77+
78+
# Book Author
79+
lb3 = Label(labelFrame,text="Author : ", bg='black', fg='white')
80+
lb3.place(relx=0.05,rely=0.50, relheight=0.08)
81+
82+
bookInfo3 = Entry(labelFrame)
83+
bookInfo3.place(relx=0.3,rely=0.50, relwidth=0.62, relheight=0.08)
84+
85+
# Book Status
86+
lb4 = Label(labelFrame,text="Status(Avail/issued) : ", bg='black', fg='white')
87+
lb4.place(relx=0.05,rely=0.65, relheight=0.08)
88+
89+
bookInfo4 = Entry(labelFrame)
90+
bookInfo4.place(relx=0.3,rely=0.65, relwidth=0.62, relheight=0.08)
91+
92+
#Submit Button
93+
SubmitBtn = Button(root,text="SUBMIT",bg='#d1ccc0', fg='black',command=bookRegister)
94+
SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
95+
96+
quitBtn = Button(root,text="Quit",bg='#f7f1e3', fg='black', command=root.destroy)
97+
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
98+
99+
root.mainloop()
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from tkinter import *
2+
from PIL import ImageTk,Image
3+
from tkinter import messagebox
4+
import pymysql
5+
6+
# Add your own database name and password here to reflect in the code
7+
mypass = "root"
8+
mydatabase="db"
9+
10+
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
11+
cur = con.cursor()
12+
13+
# Enter Table Names here
14+
issueTable = "books_issued"
15+
bookTable = "books" #Book Table
16+
17+
18+
def deleteBook():
19+
20+
bid = bookInfo1.get()
21+
22+
deleteSql = "delete from "+bookTable+" where bid = '"+bid+"'"
23+
deleteIssue = "delete from "+issueTable+" where bid = '"+bid+"'"
24+
try:
25+
cur.execute(deleteSql)
26+
con.commit()
27+
cur.execute(deleteIssue)
28+
con.commit()
29+
messagebox.showinfo('Success',"Book Record Deleted Successfully")
30+
except:
31+
messagebox.showinfo("Please check Book ID")
32+
33+
34+
print(bid)
35+
36+
bookInfo1.delete(0, END)
37+
root.destroy()
38+
39+
def delete():
40+
41+
global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,root
42+
43+
root = Tk()
44+
root.title("Library")
45+
root.minsize(width=400,height=400)
46+
root.geometry("600x500")
47+
48+
49+
Canvas1 = Canvas(root)
50+
51+
Canvas1.config(bg="#006B38")
52+
Canvas1.pack(expand=True,fill=BOTH)
53+
54+
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
55+
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
56+
57+
headingLabel = Label(headingFrame1, text="Delete Book", bg='black', fg='white', font=('Courier',15))
58+
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
59+
60+
labelFrame = Frame(root,bg='black')
61+
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
62+
63+
# Book ID to Delete
64+
lb2 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
65+
lb2.place(relx=0.05,rely=0.5)
66+
67+
bookInfo1 = Entry(labelFrame)
68+
bookInfo1.place(relx=0.3,rely=0.5, relwidth=0.62)
69+
70+
#Submit Button
71+
SubmitBtn = Button(root,text="SUBMIT",bg='#d1ccc0', fg='black',command=deleteBook)
72+
SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
73+
74+
quitBtn = Button(root,text="Quit",bg='#f7f1e3', fg='black', command=root.destroy)
75+
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
76+
77+
root.mainloop()
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
from tkinter import *
2+
from PIL import ImageTk,Image
3+
from tkinter import messagebox
4+
import pymysql
5+
6+
# Add your own database name and password here to reflect in the code
7+
mypass = "root"
8+
mydatabase="db"
9+
10+
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
11+
cur = con.cursor()
12+
13+
# Enter Table Names here
14+
issueTable = "books_issued"
15+
bookTable = "books"
16+
17+
#List To store all Book IDs
18+
allBid = []
19+
20+
def issue():
21+
22+
global issueBtn,labelFrame,lb1,inf1,inf2,quitBtn,root,Canvas1,status
23+
24+
bid = inf1.get()
25+
issueto = inf2.get()
26+
27+
issueBtn.destroy()
28+
labelFrame.destroy()
29+
lb1.destroy()
30+
inf1.destroy()
31+
inf2.destroy()
32+
33+
34+
extractBid = "select bid from "+bookTable
35+
try:
36+
cur.execute(extractBid)
37+
con.commit()
38+
for i in cur:
39+
allBid.append(i[0])
40+
41+
if bid in allBid:
42+
checkAvail = "select status from "+bookTable+" where bid = '"+bid+"'"
43+
cur.execute(checkAvail)
44+
con.commit()
45+
for i in cur:
46+
check = i[0]
47+
48+
if check == 'avail':
49+
status = True
50+
else:
51+
status = False
52+
53+
else:
54+
messagebox.showinfo("Error","Book ID not present")
55+
except:
56+
messagebox.showinfo("Error","Can't fetch Book IDs")
57+
58+
issueSql = "insert into "+issueTable+" values ('"+bid+"','"+issueto+"')"
59+
show = "select * from "+issueTable
60+
61+
updateStatus = "update "+bookTable+" set status = 'issued' where bid = '"+bid+"'"
62+
try:
63+
if bid in allBid and status == True:
64+
cur.execute(issueSql)
65+
con.commit()
66+
cur.execute(updateStatus)
67+
con.commit()
68+
messagebox.showinfo('Success',"Book Issued Successfully")
69+
root.destroy()
70+
else:
71+
allBid.clear()
72+
messagebox.showinfo('Message',"Book Already Issued")
73+
root.destroy()
74+
return
75+
except:
76+
messagebox.showinfo("Search Error","The value entered is wrong, Try again")
77+
78+
print(bid)
79+
print(issueto)
80+
81+
allBid.clear()
82+
83+
def issueBook():
84+
85+
global issueBtn,labelFrame,lb1,inf1,inf2,quitBtn,root,Canvas1,status
86+
87+
root = Tk()
88+
root.title("Library")
89+
root.minsize(width=400,height=400)
90+
root.geometry("600x500")
91+
92+
Canvas1 = Canvas(root)
93+
Canvas1.config(bg="#D6ED17")
94+
Canvas1.pack(expand=True,fill=BOTH)
95+
96+
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
97+
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
98+
99+
headingLabel = Label(headingFrame1, text="Issue Book", bg='black', fg='white', font=('Courier',15))
100+
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
101+
102+
labelFrame = Frame(root,bg='black')
103+
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
104+
105+
# Book ID
106+
lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
107+
lb1.place(relx=0.05,rely=0.2)
108+
109+
inf1 = Entry(labelFrame)
110+
inf1.place(relx=0.3,rely=0.2, relwidth=0.62)
111+
112+
# Issued To Student name
113+
lb2 = Label(labelFrame,text="Issued To : ", bg='black', fg='white')
114+
lb2.place(relx=0.05,rely=0.4)
115+
116+
inf2 = Entry(labelFrame)
117+
inf2.place(relx=0.3,rely=0.4, relwidth=0.62)
118+
119+
120+
#Issue Button
121+
issueBtn = Button(root,text="Issue",bg='#d1ccc0', fg='black',command=issue)
122+
issueBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
123+
124+
quitBtn = Button(root,text="Quit",bg='#aaa69d', fg='black', command=root.destroy)
125+
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
126+
127+
root.mainloop()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Library Management System
2+
3+
[Link](https://data-flair.training/blogs/library-management-system-python-project)

0 commit comments

Comments
 (0)