0% found this document useful (0 votes)
37 views9 pages

Lib Management Bhumi - Py

This document contains Python code for a library management system with the following functionality: 1. It connects to a MySQL database and defines tables for books, issued books, and returned books. 2. It includes functions for adding book details, issuing books to users, and returning books. 3. The user interface contains buttons to call these functions and includes fields to add/view book details and issue/return information.

Uploaded by

Shreyaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views9 pages

Lib Management Bhumi - Py

This document contains Python code for a library management system with the following functionality: 1. It connects to a MySQL database and defines tables for books, issued books, and returned books. 2. It includes functions for adding book details, issuing books to users, and returning books. 3. The user interface contains buttons to call these functions and includes fields to add/view book details and issue/return information.

Uploaded by

Shreyaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

from tkinter import *

from tkinter import messagebox


from AddBook import *
from IssueBook import *
from ReturnBook import *

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")

# Take n greater than 0.25 and less than 5


same=True
n=0.25

headingFrame1 = Frame(root,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.6,relheight=0.16)

headingLabel = Label(headingFrame1, text="Mumbai Library", bg='black', fg='white',


font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)

#Adding buttons

btn1 = Button(root,text="Add Book Details",bg='black', fg='white', command=addBook)


btn1.place(relx=0.28,rely=0.3, relwidth=0.45,relheight=0.1)

btn2 = Button(root,text="Issue Book",bg='black', fg='white', command = issueBook)


btn2.place(relx=0.28,rely=0.4, relwidth=0.45,relheight=0.1)

btn3 = Button(root,text="Return Book",bg='black', fg='white', command = returnBook)


btn3.place(relx=0.28,rely=0.5, relwidth=0.45,relheight=0.1)

root.mainloop()

from tkinter import *

from tkinter import messagebox


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")

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()

insertBooks = "insert into "+bookTable+"


values('"+bid+"','"+title+"','"+author+"','"+status+"')"
try:
mycursor.execute(insertBooks)
mydb.commit()
messagebox.showinfo('Success',"Book added successfully")
except:
messagebox.showinfo("Error","Can't add data into Database")

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")

# Enter Table Names here


bookTable = "books" # Book Table

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)

headingLabel = Label(headingFrame1, text="Add Books", 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.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)

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()
# Enter Table Names here
issueTable = "books_issued"
bookTable = "books"

#List To store all Book IDs


allBid = []

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()

extractBid = "select bid from "+bookTable


try:
mycursor.execute(extractBid)
mydb.commit()
for i in mydb:
allBid.append(i[0])

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")

issueSql = "insert into "+issueTable+" values ('"+bid+"','"+issueto+"')"


show = "select * from "+issueTable

updateStatus = "update "+bookTable+" set status = 'issued' 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 Issued Successfully")
root.destroy()
else:
allBid.clear()
messagebox.showinfo('Message',"Book Already Issued")
root.destroy()
return
except:
messagebox.showinfo("Search Error","The value entered is wrong, Try again")

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)

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 = 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)

# Issued To Student name


lb2 = Label(labelFrame,text="Issued To : ", bg='black', fg='white')
lb2.place(relx=0.05,rely=0.4)
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()

# Enter Table Names here


issueTable = "books_issued" #Issue Table
bookTable = "books" #Book Table

allBid = [] #List To store all Book IDs

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()

extractBid = "select bid from "+issueTable


try:
mycursor.execute(extractBid)
mydb.commit()
for i in cur:
allBid.append(i[0])

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")

issueSql = "delete from "+issueTable+" where bid = '"+bid+"'"

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)

headingLabel = Label(headingFrame1, text="Return 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 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)

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()

You might also like