Challenge

Project 1 - English Dictionary App & Library Book Management System

Question:

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. When the application is started, it displays a menu as follows:

Main Menu

Add a new word
Find the meaning
Update a word
Exit

Enter Choice:

If item 1 is selected, it should prompt for a word and then accept its meaning. This pair of word and its meaning should be stored in a file called ‘words.txt’. When item 2 is selected, it should prompt for a word, search that word in the file ‘words.txt’ and return the meaning if it is found. If the meaning is not found, it should display an appropriate message. Similarly, when choice 3 is entered, it should accept a word and update its meaning. In all the above three cases, the prompt should return to the main menu. The words and their meanings should be stored as a dictionary in words.txt, using the concept of serialization. If choice 4 is selected, a graceful exit should be performed.

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 json

choice = 1
while choice< 4:
print(""" Welcome to the English dictionary app
1)Add new word
2)find the meainf
3) update word
4)exixt """)
choice = int(input("Enter the choice: "))
if choice == 1:
word = input("Enter the word: ")
meaning = input("Rnter the meaning: ")
file = open("words.txt","w")
d={}
d[word]=meaning
json.dump(d,file)
file.close()

elif choice == 2:
word = input("Enter the word: ")
file = open("words.txt","r")
if word in d:
print("meaning of word is: ",d[word])
else:
print("word is not present in dictionary")
json.dump(d,file)
file.close()

elif choice == 3:
word = input("Enter the word to be updated: ")
up_meaning=input("Enter the updated meaning: ")
file = open("words.txt","w")
d[word]=up_meaning
json.dump(d,file)
file.close()

else:
print("Thank you for using English Dictionary app")

output:

 Welcome to the English dictionary app
    1)Add new word
    2)find the meainf
    3)  update word 
    4)exixt 
Enter the choice: 1
Enter the word: apple
Rnter the meaning: It is a fruit
 Welcome to the English dictionary app
    1)Add new word
    2)find the meainf
    3)  update word 
    4)exixt 
Enter the choice: 2
Enter the word: apple
meaning of word is:  It is a fruit
 Welcome to the English dictionary app
    1)Add new word
    2)find the meainf
    3)  update word 
    4)exixt 
Enter the choice: 3
Enter the word to be updated: apple
Enter the updated meaning: It is a healthy fruit
 Welcome to the English dictionary app
    1)Add new word
    2)find the meainf
    3)  update word 
    4)exixt 
Enter the choice: 2
Enter the word: apple
meaning of word is:  It is a healthy fruit
 Welcome to the English dictionary app
    1)Add new word
    2)find the meainf
    3)  update word 
    4)exixt 
Enter the choice: 4
Thank you for using English Dictionary app

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('....Library Management Application.... ')

def Database():
global conn, cursor
conn = sqlite3.connect('simple.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS book (book_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, Booktitle TEXT, Author TEXT,Year REAL,ISBN REAL) ")

def Add():
if BOOKTITLE.get() == "" or AUTHOR.get() == "" or YEAR.get() == "" or ISBN.get() == "" :
txt_result.config(text="Please enter the all fields",fg = "yellow")
else:
Database()
cursor.execute("INSERT INTO book(booktitle,author,year,isbn) VALUES (?,?,?,?)",(str(BOOKTITLE.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())))
conn.commit()
BOOKTITLE.set("")
AUTHOR.set("")
YEAR.set("")
ISBN.set("")
cursor.close()
conn.close()
txt_result.config(text="Record Inserted !",fg = "green")

def Display():
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM book ORDER BY author ASC ")
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 = "black")

def Delete():
Database()
cur = conn.cursor()
cur.execute('DELETE FROM book')
conn.commit()
conn.close()

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

# Variable Decalration
BOOKTITLE = StringVar()
AUTHOR = StringVar()
YEAR = StringVar()
ISBN = StringVar()

# Frame

Top = Frame(root, width = 900, height = 200,bd = 8,relief = 'raise')
Top.pack(side=TOP)
Left = Frame(root, width = 600, 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',25),text='....Library Management Application.... ',fg='blue')
txt_title.pack()
txt_booktitle = Label(Forms,text="Booktitle:",font = ('arial',16),bd=15)
txt_booktitle.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(side=TOP)

# Entery widget
booktitle = Entry(Forms,textvariable=BOOKTITLE,width=30)
booktitle.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)

# Button 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=DISABLED)
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=DISABLED)
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=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.pack()

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

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.