Challenge

Project 1 - English Dictionary App & Library Book Management System

~ PROJECT WORK ~

1A) English Dictionary App

  • The aim of this project is to create an English Dictionary app that returns definitions of English words.
  • Sample image of output :

  • The code for above is -

import json
from IPython.display import clear_output

def add_word():
word=input(' >| Enter the word dear : ')
fact=open('words1.txt','r')
neptune=json.load(fact)
if word in neptune:
clear_output()
print('WORD ALREADY EXISTS IN DICTIONARY')
greet()
dictionary()
mainmenu()

else:
word1=input('Enter the meaning of the word :')
if word[0].isalpha() and word1[0].isalpha():
fact=open('words1.txt','r')
neptune=json.load(fact)
neptune[word]=word1
fact1=open('words1.txt','w')
json.dump(neptune,fact1)
fact1.close()
fact.close()
clear_output()
print('-'*30)
print(' ~|~ SUCCESFULLY ADDED IN DICTIONARY ~|~ ','{',word,':',word1,'}')
print('-'*30)
greet()
dictionary()
mainmenu()



else:
clear_output()
print(' ... ^ Invalid input DEAR ^....')
print('-'*30)
greet()
dictionary()
mainmenu()


def find_word():
print('-'*50)
word2=input(' >| Enter the word you want meaning for :')
fact=open('words1.txt','r')
neptune=json.load(fact)
if word2 in neptune:
clear_output()
fact=open('words1.txt','r')
neptune=json.load(fact)
print(word2,' : ',neptune[word2])
fact.close()
print('-'*50)
greet()
dictionary()
mainmenu()

else:
clear_output()
print('-'*46)
print(' |.|.| WORD NOT EXISTS IN DICTIONARY |.|.|')
print('-'*46)
greet()
dictionary()
mainmenu()


def update_word():
word3=input(' > Enter the word u want to update : ')
fact4=open("words1.txt",'r')
earth=json.load(fact4)
if word3 not in earth:
clear_output()
print('-'*30)
print(' |.|.| WORD NOT EXISTS IN DICTIONARY |.|.|')
print('-'*30)
greet()
dictionary()
mainmenu()



else:
word4=input(' >| Enter the meaning of that word : ')
if word4[0].isalpha():
fact5=open('words1.txt','w')
earth[word3]=word4
json.dump(earth,fact5)
fact5.close()
clear_output()
print('-'*30)

print(' ` SUCCESFULLY UPDATED IN DICTIONARY ` ','{',word3,':',word4,'}')
print('-'*30)
greet()
dictionary()
mainmenu()

else:
clear_output()

print('-'*25)

print(' ... ^ INVALID INPUT DEAR ^....')

print('-'*30)
greet()
dictionary()
mainmenu()


def Exit():
print(' n -`|`- THANK YOU for using the Dictionary -`|`- n n -`|`- I hope u find this Dictionary helpful -`|`- n')
return exit

def greet():
'''
____________________________________

~ WELCOME ~
`-`-`-``-`-`-`-`-`-`-`-`-`-`-`-`-`-`
ENGLISH DICTIONARY APP
-`-`-`-`-`-`-`-`-`-`-`-`-`-`-`-`-`-`
____________________________________


--------------------------| MAIN-MENU |--------------------------

1.Add a new word to dictionary

2.Find the meaning of the word

3.Update the word in dictionary

4.Exit
-------------------------------||||-------------------------------

'''
print(greet.__doc__)
greet()

def dictionary():
pluto=open("words1.txt","r")
lines=pluto.readlines()
for line in lines:
print(' ---` DICTIONARY `---- '.center(115,'-'))
print('n')
print(line,'n')
print(' ---` DICTIONARY `---- '.center(115,'-'))
pluto.close()
dictionary()

def mainmenu():

choice=input('n >| Enter your choice :')

if choice.isdigit():
if int(choice)==1:
print('-'*50)
print(' You selected to add the word ')
add_word()
print('-'*50)
elif int(choice)==2:
print('-'*50)
print('You selected choice to find the word ')
print('-'*50)
find_word()
print('-'*50)
elif int(choice)==3:
print('-'*50)
print('You selected the choice to update the word ')
print('-'*25)
update_word()
print('-'*25)
elif int(choice)==4:
clear_output()
print('n')
print('-'*36)
Exit()
print('-'*36)
elif int(choice)<=0 or int(choice)>4:
clear_output()
print('n _-`|`-_ Enter the choice from list of options mentioned above dear _-`|`-_ n')
greet()
dictionary()
mainmenu()

else:
clear_output()
print(' n .|||. Enter valid choice Dear .|||. n ')
greet()
dictionary()
mainmenu()


mainmenu()

1B) Library Book Management System

  • The aim of this project is to develop an Library Book Management System using frontend GUI - Tkinter and backend database implemented in SQLite3.
  • Sample image of output :

  • The code for above is -

# ======================== Libraries used===========================
from tkinter import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessagebox


#========================== methods ===========================

def Database():
global conne,cursor
conne=sqlite3.connect('libraryapp.db')
cursor=conne.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS dataitems(Booktitle TEXT , Author TEXT, Year INTEGER,ISBN INTEGER)")



def Addbook():
if Booktitle.get()=='' or Author.get()=='' or Year.get()==0 or ISBN.get()==0:
message.config(text=" Please , Enter all the fields Dear ",fg='blue',bg='yellow')
remove()
else:
if ISBN.get()!=0:
Database()
cursor.execute('SELECT * FROM dataitems WHERE ISBN=?',(ISBN.get(),))
rows=cursor.fetchall()
if len(rows)>0:
message.config(text="~ Book with ISBN already exists ~",fg="blue",bg="yellow")
remove()
conne.close()
else:
Database()
cursor.execute("INSERT INTO dataitems(Booktitle,Author,Year,ISBN)VALUES(?,?,?,?)",(Booktitle.get(),Author.get(),Year.get(),ISBN.get()))
conne.commit()
Booktitle.set("")
Author.set("")
Year.set("")
ISBN.set("")
cursor.close()
remove()
message.config(text=" ~ Book is added succesfully into Library ~",fg="blue",bg="yellow")
conne.close()

def display():
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM dataitems")
fetch=cursor.fetchall()
for data in fetch:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
message.config(text=" ~ These are the books available in library ~ ",fg="blue",bg="yellow")
remove()
cursor.close()



def search():
tree.delete(*tree.get_children())
Database()
if ISBN.get()!=0 :
cursor.execute('SELECT * FROM dataitems WHERE ISBN=?',(ISBN.get(),))
rows=cursor.fetchall()
if len(rows)>0:
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
message.config(text="~ Succesfully fetched book from library ~",fg="blue",bg="yellow")
else:
message.config(text="~ Invalid details. Try again ~",fg="blue",bg="yellow")
remove()
conne.close()

elif Booktitle.get()!='' and Author.get()!='' and Year.get()!=0 :
cursor.execute('SELECT * FROM dataitems WHERE Booktitle=? AND Author=? AND Year=?',(Booktitle.get(),Author.get(),Year.get()))
rows=cursor.fetchall()
if len(rows)>0:
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
message.config(text="~ Succesfully fetched book from library ~",fg="blue",bg="yellow")
else:
message.config(text="~ Invalid details. Try again~",fg="blue",bg="yellow")
remove()
conne.close()

elif Author.get()!='' and Year.get()!=0:
cursor.execute('SELECT * FROM dataitems WHERE Author=? AND Year=?',(Author.get(),Year.get()))
rows=cursor.fetchall()
if len(rows)>0:
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
message.config(text="~ Succesfully fetched book from library ~",fg="blue",bg="yellow")
else:
message.config(text="~ Invalid details. Try again~",fg="blue",bg="yellow")
remove()
message.config(text="~ Succesfully fetched book from library ~",fg="blue",bg="yellow")
conne.close()

elif Booktitle.get()!='' and Year.get()!=0 :
cursor.execute('SELECT * FROM dataitems WHERE Booktitle=? AND Year=?',(Booktitle.get(),Year.get()))
rows=cursor.fetchall()
if len(rows)>0:
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
message.config(text="~ Succesfully fetched book from library ~",fg="blue",bg="yellow")
else:
message.config(text="~ Invalid details. Try again~",fg="blue",bg="yellow")
remove()
conne.close()

elif Booktitle.get()!='' or Author.get()!='' or Year.get()!=0 :
cursor.execute('SELECT * FROM dataitems WHERE Booktitle=? OR Author=? OR Year=?',(Booktitle.get(),Author.get(),Year.get()))
rows=cursor.fetchall()
if len(rows)==0:
message.config(text="~ Invalid details. Try again ~",fg="blue",bg="yellow")
else:
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
message.config(text=" ~ Succesfully fetched book from library ~ ",fg="blue",bg="yellow")
remove()
conne.close()

elif Booktitle.get()=='' and Author.get()=='' and Year.get()==0 and ISBN.get()==0:
message.config(text="~ Enter atleast single field to search a book from library ~",fg="blue",bg="yellow")
remove()
conne.close()


def issuebook():
Database()
selec=tree.selection()
if len(selec)>0:
tree.delete(selec)
message.config(text="~ Book Issued Succesfully~",fg="blue",bg="yellow")
else:
message.config(text="~ Select a book from the library ~",fg="blue",bg="yellow")
remove()
conne.close()

def deletebook():
tree.delete(*tree.get_children())
Database()
if ISBN.get()!=0:
cursor.execute('DELETE FROM dataitems WHERE ISBN=?',(ISBN.get(),))
conne.commit()
message.config(text="~ Deleted book from the library ~",fg="blue",bg="yellow")
else:
message.config(text=' ~ Enter ISBN of book to delete from library ~')
remove()
conne.close()

def remove():
ent1.delete(0,END)
ent2.delete(0,END)
ent3.delete("0","end")
ent3.insert(0,0)
ent4.delete("0","end")
ent4.insert(0,0)

def Exit():
result=tkMessagebox.askquestion('Warning',"Do u want to exit from library ?",icon='warning')
if result=='yes':
root.destroy()

#======================== window name ==========================
root=Tk()
root.title('..|| A Library Application ||..')

#======================== Variable Declaration ================================

Booktitle=StringVar()
Author=StringVar()
Year=IntVar()
ISBN=IntVar()

#============================= Frames ============================

Top=Frame(root,width=1000,height=50,bd=8,relief='raise')
Top.pack(side=TOP)


labe=Label(Top,text='...|| Library Management Application ||...')
labe.pack()
labe.config(font=("Courier",24),fg="yellow",bg="grey")

Left=Frame(root,width=600,height=400,bd=8,relief='raise',bg="grey")
Left.pack(side=LEFT)

Right=Frame(root,width=600,height=600,bd=8,relief='raise',bg="black")
Right.pack(side=RIGHT)

Forms=Frame(Left,width=600,height=500)
Forms.pack(side=TOP)

Buttons=Frame(Left,width=310,height=70,bd=8,relief='raise',bg="white")
Buttons.pack(side=BOTTOM)

#========================= Label Widget =================================

lab1=Label(Forms,text='Booktitle :',font=('Courier',20),bd=16,fg="black")
lab1.grid(row=0,column=0)

lab2=Label(Forms,text='Author :',font=('Courier',20),bd=16,fg="black")
lab2.grid(row=1,column=0)

lab3=Label(Forms,text='Year :',font=('Courier',20),bd=16,fg="black")
lab3.grid(row=2,column=0)

lab4=Label(Forms,text='ISBN :',font=('Courier',20),bd=16,fg="black")
lab4.grid(row=3,column=0)

message=Label(Buttons)
message.pack(side=TOP)


# ======================= Entry Widget ====================================

ent1=Entry(Forms,textvariable=Booktitle,width=40,font=('Courier',13),fg="blue",bg="yellow")
ent1.grid(row=0,column=1)

ent2=Entry(Forms,textvariable=Author,width=40,font=('Courier',13),fg="blue",bg="yellow")
ent2.grid(row=1,column=1)

ent3=Entry(Forms,textvariable=Year,width=40,font=('Courier',13),fg="blue",bg="yellow")
ent3.grid(row=2,column=1)

ent4=Entry(Forms,textvariable=ISBN,width=40,font=('Courier',13),fg="blue",bg="yellow")
ent4.grid(row=3,column=1)


#===================== Button Widget ========================

but1=Button(Buttons,width=14,text='Display',command=display)
but1.pack(side=LEFT)

but2=Button(Buttons,width=14,text='Search',command=search)
but2.pack(side=LEFT)

but3=Button(Buttons,width=14,text='Add',command=Addbook)
but3.pack(side=LEFT)

but4=Button(Buttons,width=14,text='Issue',command=issuebook)
but4.pack(side=LEFT)

but5=Button(Buttons,width=14,text='Delete',command=deletebook)
but5.pack(side=LEFT)

but6=Button(Buttons,width=14,text='Exit',command=Exit)
but6.pack(side=LEFT)

# ================== List Widget ==============================

scrollbary=Scrollbar(Right,orient=VERTICAL)
scrollbarx=Scrollbar(Right,orient=HORIZONTAL)


tree=ttk.Treeview(Right,columns=("Booktitle","Author","Year","ISBN"))

scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT, fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM,fill=X)

tree.heading('Booktitle',text='Booktitle',anchor=W)
tree.column('#0',stretch=NO,minwidth=0,width=0)

tree.heading('Author',text='Author',anchor=W)
tree.column('#1',stretch=NO,minwidth=0,width=200)

tree.heading('Year',text='Year',anchor=W)
tree.column('#2',stretch=NO,minwidth=0,width=150)

tree.heading('ISBN',text='ISBN',anchor=W)
tree.column('#3',stretch=NO,minwidth=0,width=120)

tree.pack()


#========================== INITIALISATION ================================
if __name__=='__main__':
root.mainloop()

Kindly , review the Project.

regards,

Sai Sumanth Reddy

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.