Project 1 - English Dictionary App & Library Book Management System
# English Dictionary App
import os
import json
fileName = "Dictionary" #input('Please enter a File name ')
if os.path.isfile(fileName):
f = open(fileName,'a')
print(' File already Exists \n')
else:
f = open(fileName,'w')
dic = {'add':'sum'}
json.dump(dic,f)
f.close()
def add_new_word(word,meaning):
#creating a dictionery out of text file
f1 = open("Dictionary",'r')
temp_dict = json.load(f1)
f1.close
if word in temp_dict.keys():
print("========================================================================= \n")
print ('%s already exists if you want to update the meaning of %s use option 3' % (word,word))
print("\n ========================================================================= \n")
else:
f1_1 = open("Dictionary",'w')
temp_dict[word] = meaning
json.dump(temp_dict,f1_1)
f1_1.close
def find_meaning(word):
#creating a dictionery out of text file
# = open("Dictionary1",'w')
f2 = open("Dictionary",'r')
temp_dict = json.load(f2)
f2.close
if word in temp_dict.keys():
print("========================================================================= \n")
print ('meaning of %s is : %s' % (word,temp_dict[word]))
print("\n ========================================================================= \n")
else:
print("========================================================================= \n")
print('meaning of %s not found choose option 3 to enter its meaning' %(word))
print("\n ========================================================================= \n")
def word_update(word):
#creating a dictionery out of text file
# = open("Dictionary1",'w')
f3 = open("Dictionary",'r')
temp_dict = json.load(f3)
f3.close
if word in temp_dict.keys():
new_meaning = input("Enter the new meaning : ")
f3_1 = open("Dictionary",'w')
temp_dict[word] = new_meaning
json.dump(temp_dict,f3_1)
f3_1.close
else:
print("=========================================================================== \n")
print ('No word such as %s found in the dictionay to add its meaning use option 1\n' % (word))
print("\n ========================================================================= \n")
while True:
print("WELCOME TO THE DICTIONARY APP !! \n")
print ("Choose option 1 to add new word to the Dictionary1 \n")
print ("Choose option 2 to find the meaning of the word in the Dictionary1 \n")
print ("Choose option 3 to update the new meaning of a word \n")
print ("Choose option 4 to EXIT Dictionary1 \n")
print("\n")
option = input('choose an option from the above choises ')
if option == "1":
word1 = input('Enter the word for which you wanna add meaning for :')
#print("\n")
meaning1 = input('Enter the meaning of the above word :')
add_new_word(word1,meaning1)
elif option == "2":
word2 = input('Enter the word for whcich you wanna know the meaning : ')
find_meaning(word2)
elif option == "3":
word3 = input('Enter the word for which you wanna update meaning for :')
word_update(word3)
elif option == "4":
print("\n \n")
print("______________________________________________________")
print("THANK YOU FOR USING THE Dictionary")
print("_______________________________________________________")
print("\n \n")
break
output:
WELCOME TO THE DICTIONARY APP !! Choose option 1 to add new word to the Dictionary1 Choose option 2 to find the meaning of the word in the Dictionary1 Choose option 3 to update the new meaning of a word Choose option 4 to EXIT Dictionary1 choose an option from the above choises 2 Enter the word for whcich you wanna know the meaning : r ========================================================================= meaning of r not found choose option 3 to enter its meaning ========================================================================= WELCOME TO THE DICTIONARY APP !! Choose option 1 to add new word to the Dictionary1 Choose option 2 to find the meaning of the word in the Dictionary1 Choose option 3 to update the new meaning of a word Choose option 4 to EXIT Dictionary1 choose an option from the above choises 1 Enter the word for which you wanna add meaning for :banana Enter the meaning of the above word :yellow WELCOME TO THE DICTIONARY APP !! Choose option 1 to add new word to the Dictionary1 Choose option 2 to find the meaning of the word in the Dictionary1 Choose option 3 to update the new meaning of a word Choose option 4 to EXIT Dictionary1 choose an option from the above choises 2 Enter the word for whcich you wanna know the meaning : yellow ========================================================================= meaning of yellow not found choose option 3 to enter its meaning ========================================================================= WELCOME TO THE DICTIONARY APP !! Choose option 1 to add new word to the Dictionary1 Choose option 2 to find the meaning of the word in the Dictionary1 Choose option 3 to update the new meaning of a word Choose option 4 to EXIT Dictionary1 choose an option from the above choises 2 Enter the word for whcich you wanna know the meaning : banana ========================================================================= meaning of banana is : yellow ========================================================================= WELCOME TO THE DICTIONARY APP !! Choose option 1 to add new word to the Dictionary1 Choose option 2 to find the meaning of the word in the Dictionary1 Choose option 3 to update the new meaning of a word Choose option 4 to EXIT Dictionary1 choose an option from the above choises 4 ______________________________________________________ THANK YOU FOR USING THE Dictionary _______________________________________________________
Library Book Management System
import tkinter
from tkinter import *
import sqlite3 as sq
import tkinter.ttk as ttk
from tkinter import messagebox
root = Tk()
root.title('A Library Application')
root.geometry('1200x800')
#===================================== METHODS ==========================================
def Database():
global conn,cursor
conn = sq.connect('books.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS mybooks(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,title TEXT,author TEXT,year INTEGER,isbn INTEGER)")
def Add():
if TITLE.get()=='' or AUTHOR.get()=='' or YEAR.get()=='':
txt_result.config(text="Please Enter all the fields",fg='red')
else:
Database()
cursor.execute("INSERT INTO mybooks(title,author,year,isbn) VALUES(?,?,?,?)",(TITLE.get(),AUTHOR.get(),YEAR.get(),ISBN.get()))
conn.commit()
TITLE.set('')
AUTHOR.set('')
YEAR.set('')
ISBN.set('')
cursor.close()
conn.close()
txt_result.config(text="Record Added !",fg="green")
def Search():
if TITLE.get()=='' and AUTHOR.get()=='' and YEAR.get()=='' and ISBN.get()=='':
txt_result.config(text="Please Enter any of the details to search",fg='red')
else:
tree.delete(*tree.get_children())
Database()
cursor.execute('SELECT * FROM mybooks WHERE title=? OR author=? OR year=? OR isbn=?',(TITLE.get(),AUTHOR.get(),str(YEAR.get()),str(ISBN.get())))
rows = cursor.fetchall()
for data in rows:
tree.insert("",'end',values=(data[1],data[2],data[3],data[4]))
TITLE.set('')
AUTHOR.set('')
YEAR.set('')
ISBN.set('')
cursor.close()
txt_result.config(text="Search completed and results displayed !",fg='green')
def Display():
tree.delete(*tree.get_children())
Database()
cursor.execute('SELECT * FROM mybooks')
fetch = cursor.fetchall()
for data in fetch:
tree.insert("",'end',values=(data[1],data[2],data[3],data[4]))
cursor.close()
txt_result.config(text="Successfully fetched data !",fg='blue')
def Exit():
if messagebox.askokcancel("Quit", "Do you want to Exit?"):
root.destroy()
exit()
def Delete():
if TITLE.get()=='' and AUTHOR.get()=='' and YEAR.get()=='' and ISBN.get()=='':
txt_result.config(text="Please Enter any of the details to delete",fg='red')
else:
Database()
cursor.execute('DELETE FROM mybooks WHERE title=? OR author=? OR year=? OR isbn=?',(TITLE.get(),AUTHOR.get(),YEAR.get(),str(ISBN.get())))
conn.commit()
TITLE.set('')
AUTHOR.set('')
YEAR.set('')
ISBN.set('')
cursor.close()
conn.close()
txt_result.config(text="Successfully deleted data and removed completely from the system !",fg='blue')
def Issue():
if TITLE.get()=='' or AUTHOR.get()=='' or YEAR.get()=='':
txt_result.config(text="Please Enter all the fields",fg='red')
else:
TITLE.set('')
AUTHOR.set('')
YEAR.set('')
ISBN.set('')
txt_result.config(text="Successfully Issued the Book...!",fg="black")
#====================================VARIABLE DECLARATION===================================
TITLE = StringVar()
AUTHOR = StringVar()
YEAR = StringVar()
ISBN = StringVar()
#=======================================FRAME=====================================
Top = Frame(root,width=1200,height=100,bg='blue', bd=8, relief='raise')
Top.pack(side=TOP)
Left = Frame(root, width=1000, height=800,bg='red', bd=8, relief='raise')
Left.pack(side=LEFT)
Right = Frame(root,width=300,height=800,bg='yellow', bd=8,relief='raise')
Right.pack(side=RIGHT)
Forms = Frame(Left,width=1000,height=800)
Forms.pack(side=TOP)
Buttons = Frame(Left,width=1000,height=100,bd=8,relief='raise')
Buttons.pack(side=BOTTOM)
# ================================= LABEL WIDGET ======================================
main_title =Label(Top,width=1000,font=('arial',24),text=".....Library Management Application.....")
main_title.pack()
txt_title = Label(Forms, text="Booktitle:",font=('arial',16),bd=15)
txt_title.grid(row=0, stick="e")
txt_author = Label(Forms, text="Author:",font=('arial',16),bd=15)
txt_author.grid(row=1, stick="e")
txt_year = Label(Forms, text="Year:",font=('arial',16),bd=15)
txt_year.grid(row=2, stick="e")
txt_isbn = Label(Forms, text="ISBN:",font=('arial',16),bd=15)
txt_isbn.grid(row=3, stick="e")
txt_result = Label(Buttons)
txt_result.pack()
# ================================= ENTRY WIDGET ==========================================
title = Entry(Forms,textvariable=TITLE, width=30)
title.grid(row=0,column=1)
author = Entry(Forms,textvariable=AUTHOR, width=30)
author.grid(row=1,column=1)
year = Entry(Forms,textvariable=YEAR, width=30)
year.grid(row=2,column=1)
isbn = Entry(Forms,textvariable=ISBN, width=30)
isbn.grid(row=3,column=1)
# ============================ BUTTONS WIDGET ================================================
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",command=Issue)
btn_issue.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 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.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=200)
tree.column('#2', stretch=NO, minwidth=0, width=100)
tree.column('#3', stretch=NO, minwidth=0, width=50)
tree.column('#4', stretch=NO, minwidth=0, width=100)
tree.pack()
# ==============================INITIALIZATION ===============================================
if __name__=='__main__':
root.mainloop()
output: