English Dictionary App & Library Book Management System in PYTHON
- Library Book Management System will be implemented with the front end GUI developed using Tkinter and the backend database implemented in SQLite.
- It is a single window tkinter GUI application which will implement CRUD( create, read, update, delete) operations on a ‘books’ database, in SQLite.
- The window will contain text widgets to accept / display book title, author, year of publication, ISBN (optional) and a large text area/ list box to display the records which match the search criteria
________________________________________________________________________________________
THIS IS THE SOURCE CODE:
from tkinter import *
import tkinter as tk
from sqlite3 import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMassgeBox
fullframe=Tk()
fullframe.title('Library Managment System')
conn=sqlite3.connect('books.db')
cursorobj=conn.cursor()
cursorobj.execute("CREATE TABLE IF NOT EXISTS librarytable(booktitle TEXT,author TEXT,year INTEGER,isbn INTEGER)")
cursorobj.execute("""INSERT INTO librarytable VALUES
("Chemistry: An Introduction to General, Organic, & Biological Chemistry (10th Edition)", "Timberlake.Karen C", 2008,9780136019701),
("JURAMENTADA (SAGA EL ARCHIVO DE LAS TORMENTAS 3)","Brandon Sanderson",2018,9788417347000),
("LA VIDA INVISIBLE DE ADDIE LARUE","V.e. Schwab",2020,9788416517374),
("EL OJO DEL MUNDO (LA RUEDA DEL TIEMPO Nº 1)","Robert Jordan",2019,9788445007006),
("EL MAPA DE LAS ISLAS","Alastair Bonnett",2022,9788419172105),
("ENHORABUENA POR TU FRACASO (EJEMPLAR FIRMADO POR EL AUTOR)","Arturo Gonzalez Campos",2022,2910025142747),
("LA FRONTERA INVISIBLE","Javier Reverte",2022,9788401027345),
("ESCUADRON CIELO: LA COLECCION","Brandon Sanderson",2022,9788418037757),
("EL IMPERIO FINAL (NACIDOS DE LA BRUMA-MISTBORN) (ED. ILUSTRADA)","Brandon Sanderson",2021,9788418037214),
("ENHORABUENA POR TU FRACASO","Arturo Gonzalez Campos",2022,9788418051197),
("MONA LISA ACELERADA Nº 03/03 TRILOGIA DE SPRAWL","William Gibson",2022,9788445009420),
("CRONICAS DE LA DRAGONLANCE Nº 01/03 EL RETORNO DE LOS DRAGONES","Margaret Weis",2022,9788445011041),
("CRONICAS DE LA DRAGONLANCE Nº 02/03 LA TUMBA DE HUMA","Margaret Weis",2022,9788445011102),
("EL HEROE DE LAS ERAS (SAGA NACIDOS DE LA BRUMA 3)","Brandon Sanderson",2016,9788466658911),
("LA CITA","Emilia Pardo Bazan",2021,9788418451812),
("EL HEROE DE LAS ERAS (NACIDOS DE LA BRUMA-MISTBORN [EDICION ILUST RADA] 3)","Brandon Sanderson",2021,9788418037290),
("VEINTICUATRO HORAS EN EL MADRID DE GALDOS","Brandon Sanderson",2010,9788492628902),
("LA MALDICION DE HILL HOUSE","Shirley Jackson",2019,9788494836695),
("EXHALACION","Ted Chiang",2020,9788417517793),
("EL RITMO DE LA GUERRA (EL ARCHIVO DE LAS TORMENTAS 4)","Brandon Sanderson",2020,9788417347932),
("SINSONTE","Walter Tevis",2022,9788418668371)
""")
conn.commit()
def database():
global conn,cursorobj
conn=sqlite3.connect('books.db')
cursorobj=conn.cursor()
cursorobj.execute("CREATE TABLE IF NOT EXISTS librarytable(booktitle TEXT,author TEXT,year INTEGER,isbn INTEGER)")
conn.commit()
def displaybook():
tree.delete(*tree.get_children())
database()
cursorobj.execute("SELECT * FROM librarytable ORDER BY booktitle ASC")
fetch=cursorobj.fetchall()
for data in fetch:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
cursorobj.close()
conn.close()
tk.messagebox.showinfo('Liabrary','Data fetched')
#print(fetch)
cursorobj=conn.cursor()
cursorobj.execute("SELECT * FROM librarytable")
def searchbook():
titleauthor=((author.get()).title())
titlebookname=((booktitle.get()).title())
titleisbn=((isbn.get()).title())
tree.delete(*tree.get_children())
database()
fetch=cursorobj.fetchall()
count=0
for data in fetch:
if(titlebookname==data[0]) and (titleauthor==data[1]) and (str(year.get())==str(data[2])) and (str(titleisbn)==str(data[3])):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(titlebookname==data[0]):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(titleauthor==data[1]):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(str(publishedyear.get())==str(data[2])):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(str(titleisbn)==str(data[3])):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
if(count==0):
tk.messagebox.showinfo('Library','No book like this in library')
cursorobj.close()
conn.close()
author.set("")
booktitle.set("")
year.set("")
isbn.set("")
def addbook():
database()
titlebookname=((booktitle.get()).title())
titleauthor=((author.get()).title())
titlepublishedyear=str(year.get())
titleisbn=str(isbn.get())
#ursorobj.execute("INSERT INTO librarytable VALUES(?,?,?,?)",(titlebookname,titleauthor,titlepublishedyear,titleisbn))
#print(titlebookname)
if ((titlebookname=='') or (titleauthor=='') or (titlepublishedyear=='') or (titleisbn)==''):
tk.messagebox.showinfo('Library','Please fill all the details')
else:
database()
cursorobj.execute("INSERT INTO librarytable(booktitle,author,year,isbn) VALUES(?,?,?,?)",(titlebookname,titleauthor,titlepublishedyear,titleisbn))
conn.commit()
author.set("")
booktitle.set("")
year.set("")
isbn.set("")
cursorobj.close()
conn.close()
tk.messagebox.showinfo('Library','Values inserted')
cursorobj=conn.cursor()
cursorobj.execute("SELECT * FROM librarytable")
def deletebook():
titleauthor=((author.get()).title())
titlebookname=((booktitle.get()).title())
titleisbn=((isbn.get()).title())
titlepublishedyear=(year.get().title())
tree.delete(*tree.get_children())
database()
fetch=cursorobj.fetchall()
count=0
for data in fetch:
if ((titlebookname==data[0])and (titleauthor==data[1])and (str(titlepublishedyear)==str(data[2])) and (str(titleisbn)==str(data[3]))):
tempa=("'"+str(titlebookname)+"'")
tempb=("'"+str(titleauthor)+"'")
tempp=("'"+str(titlepublishedyear)+"'")
tempi=("'"+str(titleisbn)+"'")
temp1="DELETE FROM librarytable WHERE booktitle= "+tempa +"and author= "+tempb +"and year= "+tempp +"and isbn= "+tempi
cursorobj.execute(temp1)
conn.commit()
count+=1
if(count==0):
tk.messagebox.showinfo('Library','No data with this name')
else:
tk.messagebox.showinfo('Library','Book deleted')
author.set("")
booktitle.set("")
year.set("")
isbn.set("")
conn.commit()
cursorobj.close()
conn.close()
cursorobj=conn.cursor()
cursorobj.execute("SELECT * FROM librarytable")
def issuebook():
titleauthor=((author.get()).title())
titlebookname=((booktitle.get()).title())
titleisbn=((isbn.get()).title())
titlepublishedyear=(year.get().title())
tree.delete(*tree.get_children())
fetch=cursorobj.fetchall()
cursorobj.execute("DELETE FROM librarytable")
count=0
for data in fetch:
if(titlebookname==data[0])and (titleauthor==data[1])and (titlepublishedyear==str(data[2])) and (titleisbn==str(data[3])):
if(count==0):
count+=1
tk.messagebox.showinfo('Library','Book issued')
else:
cursorobj.execute("INSERT INTO librarytable(booktitle,author,year,isbn) VALUES(?,?,?,?)",(data[0],data[1],data[2],data[3]))
conn.commit()
else:
cursorobj.execute("INSERT INTO librarytable(booktitle,author,year,isbn) VALUES(?,?,?,?)",(data[0],data[1],data[2],data[3]))
conn.commit()
if(count==0):
tk.messagebox.showinfo('Library','No book with this detail in library')
author.set("")
booktitle.set("")
publishedyear.set("")
isbn.set("")
conn.commit()
cursorobj.close()
conn.close()
def Exit():
result=tkMassgeBox.askquestion('Library','Do you want to exit?',icon='warning')
if(result=='yes'):
fullframe.destroy()
else:
tk.messagebox.showinfo('Library','You will now return to the application screen')
#=============================Frames==================================================================
TitleFrame=Frame(fullframe,width=1350,padx=20,bd=20,relief=RIDGE,bg='grey85')
TitleFrame.pack(side=TOP)
lblTitle=Label(TitleFrame,width=45,font=('Lucida Sans',40),text='...Library Managment Application...',padx=12, fg='#000')
lblTitle.grid()
LeftFrame=Frame(fullframe,bd=20,width=930,height=520,padx=20,relief=RIDGE,bg='red')
LeftFrame.pack(side=LEFT)
ButtonFrame=Frame(LeftFrame,bd=20,padx=20,relief=RIDGE,bg='grey85')
ButtonFrame.pack(side=BOTTOM)
Form=Frame(LeftFrame,bd=20,width=620,height=520,padx=20,bg='grey85')
Form.pack()
RightFrame=Frame(fullframe,bd=20,width=620,height=520,padx=20,relief=RIDGE,bg='yellow')
RightFrame.pack(side=RIGHT)
#===========================================Variables===========================================
author=StringVar()
booktitle=StringVar()
year=StringVar()
isbn=StringVar()
#===========================================Label&Entry===========================================
lbl_authorname=Label(Form,text="Booktitle:",font=('Rockwell',18,'bold'),fg='#f00')
lbl_authorname.grid(row=0,column=0,sticky='w')
entry_authorname=Entry(Form,textvariable=booktitle,width=35)
entry_authorname.grid(row=0,column=1)
lbl_bookname=Label(Form,text="Author:",font=('Rockwell',18,'bold'), fg='#f00')
lbl_bookname.grid(row=1,column=0,sticky='w')
entry_bookname=Entry(Form,textvariable=author,width=35)
entry_bookname.grid(row=1,column=1)
lbl_publishyear=Label(Form,text="Year:",font=('Rockwell',18,'bold'),fg='#f00')
lbl_publishyear.grid(row=2,column=0,sticky='w')
entry_publishyear=Entry(Form,textvariable=year,width=35)
entry_publishyear.grid(row=2,column=1)
lbl_ISBN=Label(Form,text="ISBN:",font=('Rockwell',18,'bold'), fg='#f00')
lbl_ISBN.grid(row=3,column=0,sticky='w')
entry_ISBN=Entry(Form,textvariable=isbn,width=35)
entry_ISBN.grid(row=3,column=1)
#===========================================Buttons===========================================
but_view=Button(ButtonFrame,text="Display",width=9,font=('Rockwell',15),command=displaybook,bg='grey85', fg='#000')
but_view.grid(row=1,column=0)
but_search=Button(ButtonFrame,text="Search",width=9,font=('Rockwell',15),command=searchbook,bg='grey85', fg='#000')
but_search.grid(row=1,column=1)
but_add=Button(ButtonFrame,text="Add",width=9,font=('Rockwell',15),command=addbook,bg='grey85', fg='#000')
but_add.grid(row=1,column=2)
but_issue=Button(ButtonFrame,text="Issue",width=9,font=('Rockwell',15),command=issuebook,bg='grey85', fg='#000')
but_issue.grid(row=1,column=3)
but_delete=Button(ButtonFrame,text="Delete",width=9,font=('Rockwell',15),command=deletebook,bg='grey85', fg='#000')
but_delete.grid(row=1,column=4)
but_exit=Button(ButtonFrame,text="Exit",width=9,font=('Rockwell',15),command=Exit,bg='grey85', fg='#000')
but_exit.grid(row=1,column=5)
#===========================================Scrollbar===========================================
scrollbary=Scrollbar(RightFrame)
scrollbarx=Scrollbar(RightFrame)
col=('Book_Name','Author_Name','Published_year','ISBN')
tree=ttk.Treeview(RightFrame,columns=col,show='headings')
scrollbary=Scrollbar(RightFrame)
scrollbary.pack(side=RIGHT,fill=Y)
scrollbarx=Scrollbar(RightFrame)
scrollbarx.pack(side=BOTTOM,fill=X)
tree.heading("Book_Name",text="Booktitle",anchor=W)
tree.heading("Author_Name",text="Author",anchor=W)
tree.heading("Published_year",text="Year",anchor=W)
tree.heading("ISBN",text="ISBN",anchor=W)
tree.column("Author_Name",minwidth=0,width=200)
tree.column("Book_Name",minwidth=0,width=200)
tree.column("Published_year",minwidth=0,width=150)
tree.column("ISBN",minwidth=0,width=200)
tree.pack(side=TOP,fill=BOTH)
fullframe.configure(bg='grey85')
fullframe.mainloop()