Lib Management Bhumi - Py
Lib Management Bhumi - Py
import mysql.connector
mydb=mysql.connector.connect(user="root",host="localhost",password="abcde",
database="unix")
if mydb.is_connected()==True:
print("connected succesfully")
else:
print("please try again")
mycursor=mydb.cursor()
mycursor.execute("USE unix")
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.6,relheight=0.16)
#Adding buttons
root.mainloop()
def bookRegister():
mycursor.execute('''Create table Register(bid INT(5),title VARCHAR(20), author
VARCHAR(20), status VARCHAR(10);''')
mydb.commit()
print("Table Created")
mycursor.execute('''Select * from Register''')
r=mycursor.fetchall()
bid = bookInfo1.get()
title = bookInfo2.get()
author = bookInfo3.get()
status = bookInfo4.get()
status = status.lower()
print(bid)
print(title)
print(author)
print(status)
root.destroy()
f=open("register.txt","w")
for i in r:
bid=i[0]
title=i[1]
author=i[2]
status=i[3]
rec=(str(bid)+str(title)+str(author)+str(status))
f.writelines(rec)
f.close()
def addBook():
global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,root
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
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,relheight=0.13)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4)
# Book ID
lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
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 = Label(labelFrame,text="Author : ", bg='black', fg='white')
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
lb4 = Label(labelFrame,text="Status(issued/return) : ", bg='black', fg='white')
lb4.place(relx=0.05,rely=0.65, relheight=0.08)
bookInfo4 = Entry(labelFrame)
bookInfo4.place(relx=0.3,rely=0.65, relwidth=0.62, 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)
root.mainloop()
# Enter Table Names here
issueTable = "books_issued"
bookTable = "books"
def issue():
mycursor.execute('''Create table Issue(bookid INT(5),issued_to VARCHAR(20);''')
mydb.commit()
print("Table Created")
mycursor.execute('''Select * from Issue''')
a=mycursor.fetchall()
global issueBtn,labelFrame,lb1,inf1,inf2,quitBtn,root,Canvas1,status
bid = inf1.get()
issueto = inf2.get()
issueBtn.destroy()
labelFrame.destroy()
lb1.destroy()
inf1.destroy()
inf2.destroy()
if bid in allBid:
checkAvail = "select status from "+bookTable+" where bid = '"+bid+"'"
mycursor.execute(checkAvail)
mydb.commit()
for i in cur:
check = i[0]
if check == 'avail':
status = True
else:
status = False
else:
messagebox.showinfo("Error","Book ID not present")
except:
messagebox.showinfo("Error","Can't fetch Book IDs")
print(bid)
print(issueto)
allBid.clear()
f=open("issue.txt","w")
for i in a:
bookid=i[0]
issued_to=i[1]
rec=(str(bookid)+str(issued_to))
f.writelines(rec)
f.close()
def issueBook():
global issueBtn,labelFrame,lb1,inf1,inf2,quitBtn,root,Canvas1,status
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,relheight=0.13)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
# Book ID
lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
lb1.place(relx=0.05,rely=0.2)
inf1 = Entry(labelFrame)
inf1.place(relx=0.3,rely=0.2, 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)
root.mainloop()
def returnn():
mycursor.execute('''Create table Return(bookid INT(5);''')
mydb.commit()
print("Table Created")
mycursor.execute('''Select * from Return''')
b=mycursor.fetchall()
global SubmitBtn,labelFrame,lb1,bookInfo1,quitBtn,root,Canvas1,status
bid = bookInfo1.get()
if bid in allBid:
checkAvail = "select status from "+bookTable+" where bid = '"+bid+"'"
mycursor.execute(checkAvail)
mydb.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:
messagebox.showinfo("Error","Can't fetch Book IDs")
print(bid in allBid)
print(status)
updateStatus = "update "+bookTable+" set status = 'avail' where bid = '"+bid+"'"
try:
if bid in allBid and status == True:
mycursor.execute(issueSql)
mydb.commit()
mycursor.execute(updateStatus)
mydb.commit()
messagebox.showinfo('Success',"Book Returned Successfully")
else:
allBid.clear()
messagebox.showinfo('Message',"Please check the book ID")
root.destroy()
return
except:
messagebox.showinfo("Search Error","The value entered is wrong, Try again")
allBid.clear()
root.destroy()
for i in b:
bookid=i[0]
rec=(str(bookid))
f.writelines(rec)
f.close()
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,relheight=0.13)
labelFrame = Frame(root,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
# Book ID to Delete
lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
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)
root.mainloop()