Challenge

Project 1 - English Dictionary App & Library Book Management System

Project 1

English Dictionary App & Library Book Management System :

1A: English Dictionary App :

This project uses the skills learnt from week 1 to week 6. The aim of this project is to create an English Dictionary app that returns definitions of English words.

import os
import json

fileName = "Dictionary1" #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("Dictionary1",'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("Dictionary1",'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("Dictionary1",'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("Dictionary1",'r')
    
    temp_dict = json.load(f3)
    
    f3.close
    
    if word in temp_dict.keys():
        new_meaning = input("Enter the new meaning : ")
        f3_1 = open("Dictionary1",'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 DICTIONARY1 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 Dictionary1")
        print("_______________________________________________________")
        print("\n \n")
        break
    




 File already Exists 

WELCOME TO THE DICTIONARY1 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 :advance
Enter the meaning of the above word :its is advance
WELCOME TO THE DICTIONARY1 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 3
Enter the word for which you wanna update meaning for :python
=========================================================================== 

No word such as python found in the dictionay to add its meaning use option 1


 ========================================================================= 

WELCOME TO THE DICTIONARY1 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 Dictionary1
_______________________________________________________

 

1B: Library Book Management System :

In this project, a 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.

from tkinter import*
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox

root = Tk()
root.title('Project 1B')




def Database():
    global conn,cursor
    conn = sqlite3.connect('simple.db')
    cursor = conn.cursor()
    cursor.execute("CREATE TABLE IF NOT EXISTS books (isbn INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, book_title TEXT, author TEXT, year TEXT)")

def Create():
    if BOOKname.get() == "" or AUTHOR.get() == "" or YEAR == "":
        txt_result.config(text="Please enter all the fields", fd="red")
    else:
        #print(BOOKname.get())
        #print(AUTHOR.get())
        #print(YEAR.get())
        Database()
        cursor.execute("INSERT INTO books (book_title,author,year) VALUES (?,?,?)",(str(BOOKname.get()),str(AUTHOR.get()),str(YEAR.get())))
        conn.commit()
        ISBN.set("")
        BOOKname.set("")
        AUTHOR.set("")
        YEAR.set("")
        cursor.close()
        conn.close()
        txt_result.config(text = "Recorded ! ",fg = "green")
        
def Read():
    tree.delete()#(*tree.get_children)
    Database()
    cursor.execute("SELECT * FROM books ORDER BY book_title")
    fetch = cursor.fetchall()
    for data in fetch:
        tree.insert('','end',values=(data[1],data[2],data[3]))
    cursor.close()
    txt_result.config(text="Successfully Fetched Data !")
    
def Update():
    Database()
    
    if BOOKname.get() != "":
        cursor.execute("UPDATE books SET book_title = ? WHERE isbn = ?",(BOOKname.get(),ISBN.get(),))
    if AUTHOR.get() != "":
        cursor.execute("UPDATE books SET author = ? WHERE isbn = ?",(AUTHOR.get(),ISBN.get(),))
    if YEAR.get() != "":
        cursor.execute("UPDATE books SET year = ? WHERE isbn = ?",(YEAR.get(),ISBN.get(),))
        
    conn.commit()
    ISBN.set("")
    BOOKname.set("")
    AUTHOR.set("")
    YEAR.set("")
    cursor.close()
    conn.close()
    #cursor.close()
    txt_result.config(text="Successfully Updated ")

    
def Delete():
    Database()
    cursor.execute("DELETE FROM books where book_title = ? or author = ? ",(BOOKname.get(),AUTHOR.get(),))
    conn.commit()
    ISBN.set("")
    BOOKname.set("")
    AUTHOR.set("")
    YEAR.set("")
    cursor.close()
    conn.close()
    #cursor.close()
    txt_result.config(text="Successfully Deleted ")

    
    
    
def Exit():
    result = tkMessageBox.askquestion('Do you want to Exit ? (y/n)', icon = 'warning')
    if result == 'yes':
        root.destroy()
        exit()
        

BOOKname = StringVar()
AUTHOR = StringVar()
YEAR = StringVar()
ISBN = IntVar()


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)

Forms = Frame(Left,width = 300, height = 450)
Forms.pack(side=TOP)

Buttons = Frame(Left, width = 300, height = 100, bd = 8, relief = 'raise')
Buttons.pack(side=BOTTOM)



#===========================LABELS========================
txt_title = Label(Top, width = 900, font=('arial',24), text = "Python Simple CRUDA Application")
txt_title.pack()
txt_bookName = Label(Forms, text = "ISBN number: ", font = ('arial',16), bd=15)
txt_bookName.grid(row=0,stick="e")
txt_bookName = Label(Forms, text = "Book's name: ", font = ('arial',16), bd=15)
txt_bookName.grid(row=1,stick="e")
txt_Author = Label(Forms, text = "Author's name: ", font = ('arial',16), bd=15)
txt_Author.grid(row=2,stick="e")
txt_Year = Label(Forms, text = "Year: ", font = ('arial',16), bd=15)
txt_Year.grid(row=3,stick="e")
txt_result = Label(Buttons)
txt_result.pack(side = TOP)

#===========================ENTERY========================
isbnum = Entry(Forms, textvariable=ISBN,width=30)
isbnum.grid(row=0,column=1)
bookname = Entry(Forms, textvariable=BOOKname,width=30)
bookname.grid(row=1,column=1)
author = Entry(Forms, textvariable=AUTHOR,width=30)
author.grid(row=2,column=1)
year = Entry(Forms, textvariable=YEAR,width=30)
year.grid(row=3,column=1)


#===========================BUTTONS========================
btn_create = Button(Buttons, width=10, text="Create", command = Create)
btn_create.pack(side=LEFT)
btn_read = Button(Buttons, width=10, text="Read", command = Read)
btn_read.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)

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

tree = ttk.Treeview(Right, columns=("Book","Author","Year"))
scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT, fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM,fill=X)
tree.heading('Book', text = 'Book', anchor =W)
tree.heading('Author', text = 'Author', anchor =W)
tree.heading('Year', text = 'Year', 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=80)
#tree.column('#4', stretch=NO, minwidth=0, width=150)
#tree.column('#5', stretch=NO, minwidth=0, width=120)
#tree.column('#6', stretch=NO, minwidth=0, width=120)
tree.pack()

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





conclusion :

thus the program is created by using anaconda navigator in jupiter notebook

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.