Project 1 - English Dictionary App & Library Book Management System
Python Dictionary App:
import json # importing the necessary modules
print('Welcome to the Dictionary App')
print('Please select your choice')
print('1. Add a word')
print('2. Find the meaning')
print('3. Update the word')
print('4. Exit')
f = open('words.txt','w+') # open file in write mode
coll_words = {}
json.dump(coll_words,f)
f.close()
while True:
n=int(input("enter a choice:"))
if n==1:
f=open('words.txt','w+')
word=input("enter a word:")
meaning=input("enter meaning:")
coll_words[word]=meaning
json.dump(coll_words,f) # loading data into file
f.close()
print("Data inserted successfully")
elif n==2:
f=open("words.txt",'r') # file open in read mode
word=input("enter a word for meaning:")
if word in coll_words:
print("meaning:",coll_words.get(word)) # printing the meaning of word
else:
print("meaning not found")
elif n==3:
f=open('words.txt','w+') # file open in write mode
word=input("enter a word:")
updated_meaning=input("enter updated meaning:")
coll_words[word]=updated_meaning
json.dump(coll_words,f)
f.close()
print("Data updated successfully")
elif n==4:
print("Thank u for choosing dictionary app")
break # if word not found then break terminates execution
else:
print('Please enter the mentioned choice') # creating the menu bar
print('1. Add a word')
print('2. Find the meaning')
print('3. Update the word')
print('4. Exit')
Sample Output:
Welcome to the Dictionary App Please select your choice 1. Add a word 2. Find the meaning 3. Update the word 4. Exit enter a choice:1 enter a word:skill lync enter meaning:elearning platform Data inserted successfully enter a choice:1 enter a word:tushar enter meaning:skill lync student Data inserted successfully enter a choice:2 enter a word for meaning:tushar meaning: skill lync student enter a choice:2 enter a word for meaning:skill lync meaning: elearning platform
Library Management System:
from tkinter import *
import sqlite3 as sq
import tkinter.ttk as ttk
import tkinter.messagebox as tkMassgeBox
def Database():
global conn,cursor
conn=connect("Library.db")
cursor=conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS lbms(author_name TEXT,book_title TEXT,year INTEGER,ISBN INTEGER)")
def display_all_records():
present.delete(*present.get_children())
Database()
cursor.execute("SELECT * FROM lbms ORDER by book_title ASC")
fetch=cursor.fetchall()
for data in fetch:
present.insert('','end',values=(data[0],data[1],data[2],data[3]))
conn.close()
Ll1.config(text="Please see the books!",fg="green")
def add_new_book():
Database()
if author_name.get(1.0,"end-1c")!="" and book_title.get(1.0,"end-1c")!="" and year.get(1.0,"end-1c")!="" and ISBN.get(1.0,"end-1c")!="":
cursor.execute("INSERT INTO lbms VALUES(?,?,?,?)",(author_name.get(1.0,"end-1c"),book_title.get(1.0,"end-1c"),int(year.get(1.0,"end-1c")),int(ISBN.get(1.0,"end-1c"))))
conn.commit()
delete()
conn.close()
Ll1.config(text="Book is added successfully!",fg="green")
else:
Ll1.config(text="Please enter all the values to add the book!",fg="red")
delete()
def Search_book():
present.delete(*present.get_children())
Database()
if str(author_name.get(1.0,"end-1c"))!="":
name="'"+str(author_name.get(1.0,"end-1c")).title()+"'"
temp="SELECT * FROM lbms WHERE author_name = "+name
cursor.execute(temp)
fetch=cursor.fetchall()
for data in fetch:
present.insert('','end',values=(data[0],data[1],data[2],data[3]))
Ll1.config(text="Please see the books!",fg="green")
elif str(book_title.get(1.0,"end-1c"))!="":
name="'"+str(book_title.get(1.0,"end-1c")).title()+"'"
temp="SELECT * FROM lbms WHERE book_title = "+name
cursor.execute(temp)
fetch=cursor.fetchall()
for data in fetch:
present.insert('','end',values=(data[0],data[1],data[2],data[3]))
Ll1.config(text="Please see the books!",fg="green")
elif str(year.get(1.0,"end-1c"))!="":
temp="SELECT * FROM lbms WHERE year = "+str(year.get(1.0,"end-1c"))
cursor.execute(temp)
fetch=cursor.fetchall()
for data in fetch:
present.insert('','end',values=(data[0],data[1],data[2],data[3]))
Ll1.config(text="Please see the books!",fg="green")
elif str(ISBN.get(1.0,"end-1c"))!="":
temp="SELECT * FROM lbms WHERE ISBN = "+str(ISBN.get(1.0,"end-1c"))
cursor.execute(temp)
fetch=cursor.fetchall()
for data in fetch:
present.insert('','end',values=(data[0],data[1],data[2],data[3]))
Ll1.config(text="Please see the books!",fg="green")
else:
Ll1.config(text="Please enter at least a single identity!",fg="red")
delete()
conn.close()
def issue_the_book():
Database()
selected_item=present.selection()
if len(selected_item)>0:
present.delete(selected_item)
Ll1.config(text="Selected book is issued!",fg="green")
else:
Ll1.config(text="Please select a book from library to issue!",fg="red")
delete()
conn.close()
def delete_book():
Database()
if author_name.get(1.0,"end-1c")=="" or book_title.get(1.0,"end-1c")=="" or year.get(1.0,"end-1c")=="" or ISBN.get(1.0,"end-1c")=="":
Ll1.config(text="Please enter all Entries!",fg="red")
delete()
else:
author='"'+str(author_name.get(1.0,"end-1c"))+'"'
book='"'+str(book_title.get(1.0,"end-1c"))+'"'
y=str(year.get(1.0,"end-1c"))
I=str(ISBN.get(1.0,"end-1c"))
temp="DELETE FROM lbms WHERE author_name LIKE "+author+" and book_title LIKE "+book+" and year = "+y+" and ISBN = "+I
cursor.execute(temp)
conn.commit()
Ll1.config(text="Book deleted successfully!",fg='green')
delete()
conn.close()
def delete():
author_name.delete("1.0","end")
book_title.delete("1.0","end")
year.delete("1.0","end")
ISBN.delete("1.0","end")
def Exit():
result=tkMassgeBox.askquestion("Do you want to exit? (y/n)",icon="warning")
if result=="yes":
root.destroy()
exit()
root=Tk()
root.geometry("900x400")
root.title("Library management system")
# creating input filelds and labels
Top=Frame(root,width=900,height=50,bd=8,relief='raise')
Top.pack(side=TOP)
Left=Frame(root,width=300,height=500,bd=8,relief='raise')
Left.pack(side=LEFT)
Right=Frame(root,width=600,height=500,bd=8,relief='raise')
Right.pack(side=RIGHT)
inner_upper=Frame(Left,width=300,height=250,bd=8,relief="raise")
inner_upper.pack(side=TOP)
L1=Label(Top,text=" Library Book Management System ",font=("arial",20))
L1.pack()
L2=Label(inner_upper,text="Author Name:",font=("arial",14))
L2.grid(row=0,column=0)
L3=Label(inner_upper,text="Book Name:",font=("arial",14))
L3.grid(row=1,column=0)
L4=Label(inner_upper,text="Published year:",font=('arial',14))
L4.grid(row=2,column=0)
L5=Label(inner_upper,text="ISBN:",font=('arial',14))
L5.grid(row=3,column=0)
author_name=Text(inner_upper,height=2,width=40)
author_name.grid(row=0,column=1)
book_title=Text(inner_upper,height=2,width=40)
book_title.grid(row=1,column=1)
year=Text(inner_upper,height=2,width=40)
year.grid(row=2,column=1)
ISBN=Text(inner_upper,height=2,width=40)
ISBN.grid(row=3,column=1)
Ll1=Label(Right)
Ll1.pack(side=BOTTOM)
inner_frame=Frame(Left,width=250,height=50,bd=8,relief='raise')
inner_frame.pack(side=BOTTOM)
Bb1=Button(inner_frame,text="View Library",command=display_all_records)
Bb1.grid(row=0,column=0)
Bb2=Button(inner_frame,text="Search",command=Search_book)
Bb2.grid(row=0,column=1)
Bb3=Button(inner_frame,text="Add New Book",command=add_new_book)
Bb3.grid(row=0,column=2)
Bb4=Button(inner_frame,text="Issue the Book",command=issue_the_book)
Bb4.grid(row=0,column=3)
Bb5=Button(inner_frame,text="Delete the Book",command=delete_book)
Bb5.grid(row=0,column=4)
Bb6=Button(inner_frame,text="Exit",command=Exit)
Bb6.grid(row=0,column=5)
scrollbary=Scrollbar(Right,orient=VERTICAL)
scrollbarx=Scrollbar(Right,orient=HORIZONTAL)
present = ttk.Treeview(Right)
scrollbary.config(command=present.yview)
scrollbary.pack(side=RIGHT,fill=Y)
scrollbarx.config(command=present.xview)
scrollbarx.pack(side=BOTTOM,fill=X)
present['columns']=("Author Name","Book Name","Published year","ISBN no")
present.column('#0', width=0, stretch=NO)
present.column('Author Name', anchor=CENTER, width=100)
present.column('Book Name', anchor=CENTER, width=100)
present.column('Published year', anchor=CENTER, width=100)
present.column('ISBN no', anchor=CENTER, width=100)
present.heading('#0', text='', anchor=CENTER)
present.heading('Author Name', text='Author Name', anchor=CENTER)
present.heading('Book Name', text='Book Name', anchor=CENTER)
present.heading('Published year', text='Published year', anchor=CENTER)
present.heading('ISBN no', text='ISBN no', anchor=CENTER)
present.pack()
root.mainloop()