Project 1 - English Dictionary App & Library Book Management System
English Dictionary App
import json
def main():
print('Main menu')
print('1 Add a new word')
print('2 Find the meaning')
print('3 Update a word ')
print('4 Exit')
def add():
word=input('Enter the word : ').lower()
meaning=input('Enter the Meaning of the word : ')
store[word]=meaning
add_to_file()
def find():
word = input('Enter the word: ').lower()
if word in store.keys():
print('Meaning',store[word])
else:
print('this words meaning is not added in dictionary')
def update():
word=input('Enter the word thats meaning to change : ').lower()
meaning=input('Enter the Meaning : ')
store[word]=meaning
add_to_file()
def readfile():
f= open('words.txt','r')
return json.load(f)
def add_to_file():
global store
f= open('words.txt','w')
json.dump(store,f)
store=readfile()
main()
while True:
print('To choose the options enter numbers given to that option')
n= int(input('Enter your choice : '))
if n==1:
add()
elif n==2:
find()
elif n==3:
update()
elif n==4:
break
else:
print('Enter a valid choice')
print('Dictionary Closed')
(Created an txt file named words.txt with an empty dictionart and added data from this app)


the code will add to the files in a dictionary and update as a dictionary.
Library Book Management System
from tkinter import *
import sqlite3
import tkinter.ttk as ttk
window =Tk()
window.title(' A Library Application')
#...........................functions.............................................
def database():
global con,cur
con=sqlite3.connect('library.db')
cur=con.cursor()
cur.execute("Create table if not exists books(bno integer primary key autoincrement,bookname TEXT,author TEXT,year integer,isbn TEXT) ")
def add():
if BookTitle.get() == ''or Author.get()==''or Year.get()=='':
label_result.config(text='Enter the fields , ISBN(optional) ',fg='red')
else:
database()
cur.execute('insert into books (bookname,author,year,isbn) values(?,?,?,?)',(str(BookTitle.get()),str(Author.get()),Year.get(),str(ISBN.get())))
con.commit()
BookTitle.set('')
Author.set('')
Year.set(0)
ISBN.set('')
cur.close()
label_result.config(text='SuccessFully Added to the List of books',fg='green')
def search():
if BookTitle.get() == ''or Author.get()==''or Year.get()=='':
label_result.config(text='Enter the fields , ISBN(optional) ',fg='red')
else:
tree.delete(*tree.get_children())
database()
cur.execute('select * from books where bookname = ? and author = ? and year = ?',(str(BookTitle.get()),str(Author.get()),Year.get()))
fetch = cur.fetchall()
for data in fetch:
tree.insert('','end',values =(data[1],data[2],data[3],data[4]))
BookTitle.set('')
Author.set('')
Year.set(0)
ISBN.set('')
cur.close()
label_result.config(text='Search Completed',fg='green')
def delete():
if BookTitle.get() == ''or Author.get()==''or Year.get()=='':
label_result.config(text='Enter the fields , ISBN(optional) ',fg='red')
else:
database()
cur.execute('delete from books where bookname=? and author=? and year=?',(str(BookTitle.get()),str(Author.get()),Year.get()))
con.commit()
BookTitle.set('')
Author.set('')
Year.set(0)
ISBN.set('')
cur.close()
label_result.config(text='Deleted SuccessFully ',fg='green')
def exit():
window.destroy()
def display():
tree.delete(*tree.get_children())
database()
cur.execute('select * from books')
fetch = cur.fetchall()
for data in fetch:
tree.insert('','end',values =(data[1],data[2],data[3],data[4]))
cur.close()
label_result.config(text='SuccessFully Displayed',fg='green')
def update():
label_result.config(text='this will update the year and author name of book you entered ',fg='blue')
if BookTitle.get() == ''or Author.get()==''or Year.get()=='':
label_result.config(text='Enter the fields , ISBN(optional) ',fg='red')
else:
database()
cur.execute('update books set year=?,author=? where bookname=?',(Year.get(),str(Author.get()),str(BookTitle.get())))
con.commit()
BookTitle.set('')
Author.set('')
Year.set(0)
ISBN.set('')
cur.close()
label_result.config(text='Updated SuccessFully ',fg='green')
#...............................variables................................
BookTitle=StringVar()
Author =StringVar()
Year=IntVar()
ISBN=StringVar()
# ..............................Frames..................................
top =Frame(window,width=800,height=50,bd=8,bg='blue',relief='raise')
top.pack(side=TOP)
left=Frame(window,width=400,height=600,bd=8,bg='red',relief='raise')
left.pack(side=LEFT)
right=Frame(window,width=600,height=500,bd=8,bg='yellow',relief='raise')
right.pack(side=RIGHT)
Form=Frame(left,width=300,height=450)
Form.pack(side=TOP)
Buttons=Frame(left,width=300,height=100,bd=8,relief='raise')
Buttons.pack(side=BOTTOM)
# ...........................label........................................
label_title=Label(top,width=800,text='..... Library Management Application.....',font=('arial',20),bd=15)
label_title.pack()
label_booktitle=Label(Form,text='Booktitle:',font=('arial',16),bd=15)
label_booktitle.grid(row =0,stick='e')
label_author=Label(Form,text='Author:',font=('arial',16),bd=15)
label_author.grid(row =1,stick='e')
label_year=Label(Form,text='Year:',font=('arial',16),bd=15)
label_year.grid(row =2,stick='e')
label_isbn=Label(Form,text='ISBN:',font=('arial',16),bd=15)
label_isbn.grid(row =3,stick='e')
label_result=Label(Buttons)
label_result.pack(side=TOP)
#.......................entry.............................
booktitle=Entry(Form,textvariable=BookTitle,width=60)
booktitle.grid(row=0,column=1)
author=Entry(Form,textvariable=Author,width=60)
author.grid(row=1,column=1)
year=Entry(Form,textvariable=Year,width=60)
year.grid(row=2,column=1)
isbn=Entry(Form,textvariable=ISBN,width=60)
isbn.grid(row=3,column=1)
#....................buttons..........................
btn_display=Button(Buttons,width=10,text='Display',command=display)
btn_display.pack(side=LEFT)
btn_search=Button(Buttons,width=10,text='Search',command=search)
btn_search.pack(side=LEFT)
btn_add=Button(Buttons,width=10,text='Add',command=add)
btn_add.pack(side=LEFT)
btn_Issue=Button(Buttons,width=10,text='Issue',state=DISABLED)
btn_Issue.pack(side=LEFT)
btn_update=Button(Buttons,width=10,text='Update',command=update)
btn_update.pack(side=LEFT)
btn_delete=Button(Buttons,width=10,text='Delete',command=delete)
btn_delete.pack(side=LEFT)
btn_exit=Button(Buttons,width=10,text='Exit',command=exit)
btn_exit.pack(side=LEFT)
#....................list................................
scrollx =Scrollbar(right,orient=VERTICAL)
scrolly=Scrollbar(right,orient=HORIZONTAL)
tree=ttk.Treeview(right,columns=('Booktitle','Author','Year','ISBN'))
scrollx.config(command=tree.xview)
scrollx.pack(side=BOTTOM,fill=X)
scrolly.config(command=tree.yview)
scrolly.pack(side=RIGHT,fill=Y)
tree.heading('Booktitle',text='Booktitle',anchor=W)
tree.heading('Author',text='Author',anchor=W)
tree.heading('Year',text='Year',anchor=W)
tree.heading('ISBN',text='ISBN',anchor=W)
tree.column('#0',stretch =NO,minwidth=0,width=0)
tree.column('#1',stretch =NO,minwidth=0,width=80)
tree.column('#2',stretch =NO,minwidth=0,width=120)
tree.column('#3',stretch =NO,minwidth=0,width=150)
tree.column('#4',stretch =NO,minwidth=0,width=160)
tree.pack()
window.mainloop()
add function


display function

search function


update function

after updating

delete function
before delete

after delete
