Project
Project
Code:
from tkinter import *
from PIL import ImageTk,Image #PIL -> Pillow
import pymysql
from tkinter import messagebox
from AddBook import *
from DeleteBook import *
from ViewBooks import *
from IssueBook import *
Code:
mypass = "root" #use your own password
mydatabase="db" #The database name
con = pymysql.connect (host="localhost",user="root",password=mypass,database=mydatabase)
#root is the username here
cur = con.cursor() #cur -> cursor
Code:
root = Tk()
root.title("Library")
root.minsize(width=400,height=400)
root.geometry("600x500")
Code:
same=True
n=0.25
# Adding a background image
background_image =Image.open("lib.jpg")
[imageSizeWidth, imageSizeHeight] = background_image.size
newImageSizeWidth = int(imageSizeWidth*n)
if same:
newImageSizeHeight = int(imageSizeHeight*n)
else:
newImageSizeHeight = int(imageSizeHeight/n)
background_image = background_image.resize((newImageSizeWidth,newImageSizeHeight),Image.ANTIALIAS)
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)
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="Welcome to \n DataFlair Library", bg='black', fg='white',
font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
ouput:
Source Code:
import pymysql
def bookRegister():
bid = bookInfo1.get()
title = bookInfo2.get()
author = bookInfo3.get()
status = bookInfo4.get()
status = status.lower()
try:
cur.execute(insertBooks)
con.commit()
except:
print(bid)
print(title)
print(author)
print(status)
root.destroy()
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")
# Add your own database name and password here to reflect in the code
mypass = "root"
mydatabase="db"
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
cur = con.cursor()
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.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.place(relx=0.05,rely=0.35, relheight=0.08)
bookInfo2 = Entry(labelFrame)
# Book Author
lb3.place(relx=0.05,rely=0.50, relheight=0.08)
bookInfo3 = Entry(labelFrame)
# Book Status
lb4.place(relx=0.05,rely=0.65, relheight=0.08)
bookInfo4 = Entry(labelFrame)
#Submit Button
SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
root.mainloop()
from tkinter import *
import pymysql
# Add your own database name and password here to reflect in the code
mypass = "root"
mydatabase="db"
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
cur = con.cursor()
bookTable = "books"
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,relheight=0.13)
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.place(relx=0.4,rely=0.9, relwidth=0.18,relheight=0.08)
root.mainloop()
Source Code :
import pymysql
# Add your own database name and password here to reflect in the code
mypass = "root"
mydatabase="db"
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
cur = con.cursor()
issueTable = "books_issued"
def deleteBook():
bid = bookInfo1.get()
try:
cur.execute(deleteSql)
con.commit()
cur.execute(deleteIssue)
con.commit()
except:
print(bid)
bookInfo1.delete(0, END)
root.destroy()
def delete():
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="#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
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.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
root.mainloop()
Issue Book
Source code :
import pymysql
# Add your own database name and password here to reflect in the code
mypass = "root"
mydatabase="db"
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
cur = con.cursor()
issueTable = "books_issued"
bookTable = "books"
allBid = []
def issue():
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()
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 == 'avail':
status = True
else:
status = False
else:
except:
try:
cur.execute(issueSql)
con.commit()
cur.execute(updateStatus)
con.commit()
root.destroy()
else:
allBid.clear()
root.destroy()
return
except:
print(bid)
print(issueto)
allBid.clear()
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.place(relx=0.05,rely=0.2)
inf1 = Entry(labelFrame)
inf1.place(relx=0.3,rely=0.2, relwidth=0.62)
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.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
root.mainloop()
Source Code :
import pymysql
# Add your own database name and password here to reflect in the code
mypass = "root"
mydatabase="db"
con = pymysql.connect(host="localhost",user="root",password=mypass,database=mydatabase)
cur = con.cursor()
def returnn():
global SubmitBtn,labelFrame,lb1,bookInfo1,quitBtn,root,Canvas1,status
bid = bookInfo1.get()
try:
cur.execute(extractBid)
con.commit()
for i in cur:
allBid.append(i[0])
if bid in allBid:
checkAvail = "select status from "+bookTable+" where bid = '"+bid+"'"
cur.execute(checkAvail)
con.commit()
for i in cur:
check = i[0]
if check == 'issued':
status = True
else:
status = False
else:
except:
print(bid in allBid)
print(status)
try:
cur.execute(issueSql)
con.commit()
cur.execute(updateStatus)
con.commit()
allBid.clear()
root.destroy()
return
except:
allBid.clear()
root.destroy()
def returnBook():
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))
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.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
root.mainloop()