Challenge

Project 1 - English Dictionary App & Library Book Management System

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.

If you want to be recognized as a professional programmer, you have to practice more and develop applications in Python which you can include in your online portfolio. To achieve this, one such comprehensive project (with two small sub-projects inside it) is added which have to be completed by every student.

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.

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.

import pickle
import json

def saveDictionary(tmp_dict):
try:
with open('words.txt', 'wb') as dictionary:
pickle.dump(tmp_dict, dictionary)
print("SUCCESS: writing to dictionary words.txt")
except Exception as e:
print(f"ERROR: {e}")


def getDictionary():
try:
with open('words.txt', 'rb') as dictionary:
tmp_dict = pickle.load(dictionary)
print("SUCCESS: reading from dictionary words.txt")
return tmp_dict
except Exception as e:
print(f"ERROR: {e}")

def addNewWord():
print("Enter a Word to add")
word = input(">>")
print(f"Enter a meaning of {word} to add")
meaning = input(">>")
dictionary = getDictionary()
dictionary[word] = meaning
saveDictionary(dictionary)
main_menu()


def findMeaning():
print("WORD FINDER:")
print("Enter a Word to find")
word = input(">>")
dictionary = getDictionary()
if word in dictionary:
print(f"Found Entry: [{word} : {dictionary[word]}]")
else:
print("ERROR: The word doesn't exist!")
findMeaning()
main_menu()


def updateWord():
print("WORD UPDATER:")
print("Enter an old Word to edit")
word = input(">>")
dictionary = getDictionary()
if word in dictionary:
print(f"Enter a New Meaning to edit [{word} : {dictionary[word]}] to:")
new_meaning = input(">>")
dictionary[word] = new_meaning
saveDictionary(dictionary)
print(f"SUCCESS: Updated to [{word} : {dictionary[word]}]")
else:
print("ERROR: The word doesn't exist! impossible to update!")
updateWord()
main_menu()


def main_menu():
print("ENGLISH DICTIONARY APP")
print("1. Add a new word")
print("2. Find the meaning")
print("3. Update a word")
print("4. Exit")
n = int(input(">>"))
if n==1:
addNewWord()
elif n==2:
findMeaning()
elif n==3:
updateWord()
elif n==4:
exit()
else:
print("ERROR: Please Enter a digit according to Menu.")
main_menu()

from tkinter import *
from PyDictionary import PyDictionary

dictionary=PyDictionary()
root=Tk()
root.title("my dictionary")
root.geometry("1080x720")
def dict():
meaning.config(text=dictionary.meaning(word.get())['Noun'][0])

Label(root, text="My Dictionary", font=(
"Poppins, 20 bold"), fg="grey").pack(pady=20)

frame = Frame(root)
Label(frame, text="Enter word: ", font=(
"Helvetica, 25 bold")).pack(side="left")
word = Entry(frame, font=("Helvetica, 25 bold"), width=30)
word.pack()
frame.pack(pady=30)

frame1 = Frame(root)
Label(frame1, text="Meaning: ", font=("Aerial, 25 bold")).pack(side=LEFT)
meaning = Label(frame1, text="", font=("Poppins, 25"))
meaning.pack()
frame1.pack(pady=30)

Button(root, text="Search", font=("Helvetica, 15 bold"), command=dict).pack()
root.mainloop()

import sqlite3

def init_db():
conn = sqlite3.connect("LBMS.db")
cursor = conn.cursor()
print("Database connection established successfully")
create_table(cursor)
return(conn, cursor)
conn.commit()
conn.close()
print("Database connection de-established successfully")


def create_table(cursor):
sql_command = """CREATE TABLE if not exists books (
title varchar(60) not null,
author varchar(30) not null,
year INTEGER not null,
ISBN INTEGER,
unique (title, author, year, ISBN));"""
cursor.execute(sql_command)


def read_table(cursor):

sql_command = "SELECT * FROM books"
cursor.execute(sql_command)
data = cursor.fetchall()
return(data)


def add_to_table(cursor, title, author, year, isbn):

sql_command = f"INSERT INTO books VALUES ('{title}', '{author}', {year}, {isbn});"
try:
cursor.execute(sql_command)
return(0, "success")
except sqlite3.IntegrityError as e:
return(111, e)
except sqlite3.OperationalError as e:
return(112, e)


def remove_from_table(cursor, title, author, year, isbn):
try:
sql_command = f'''DELETE FROM books WHERE title="{title}";'''
cursor.execute(sql_command)
sql_command = f'''DELETE FROM books WHERE author="{author}";'''
cursor.execute(sql_command)
sql_command = f'''DELETE FROM books WHERE year="{year}";'''
cursor.execute(sql_command)
sql_command = f'''DELETE FROM books WHERE isbn="{isbn}";'''
cursor.execute(sql_command)
except:
return(-1)


def search_from_table(cursor, title, author, year, isbn):

try:
cursor.execute("SELECT * FROM books WHERE title=?", (title,))
searched_titles = cursor.fetchall()
cursor.execute("SELECT * FROM books WHERE author=?", (author,))
searched_authors = cursor.fetchall()
cursor.execute("SELECT * FROM books WHERE year=?", (year,))
searched_years = cursor.fetchall()
cursor.execute("SELECT * FROM books WHERE ISBN=?", (isbn,))
searched_isbns = cursor.fetchall()
return(searched_titles + searched_authors + searched_years + searched_isbns)
except:
return(-1)


def list_all_books(listArea):
conn, cursor = init_db()
print("listing books")
books = read_table(cursor)
listArea.delete('0','end')
for i in range(len(books)):
listArea.insert(i,f"{books[i][0]}, {books[i][1]}, {books[i][2]}, {books[i][3]}")
conn.commit()
conn.close()

def search_book(listArea, title, author, year, isbn):
conn, cursor = init_db()
print("search book")
title = title.get()
author = author.get()
year = year.get()
isbn = isbn.get()
res = search_from_table(cursor, title, author, year, isbn)
if res==-1:
messagebox.showerror("Error!", "something went wrong!")
if res!=-1:
listArea.delete('0','end')
for i in range(len(res)):
listArea.insert(i,res[i])
conn.commit()
conn.close()


def add_book(title, author, year, isbn):
conn, cursor = init_db()
print("adding book")
title = title.get()
author = author.get()
year = year.get()
isbn = isbn.get()
code, error = add_to_table(cursor, title, author, year, isbn)
if code==111:
messagebox.showerror("Error!", f"Book Already Exists!\n\nerror code: {code}\nerror:{error}")
if code==112:
messagebox.showerror("Error!", f"Please, fill in the input fields appropriately.\n\ntitle: string, author: string, year: integer, year: integer.\n\nerror code: {code}\nerror:{error}")
conn.commit()
conn.close()
print("added successfully")

def issue_book(title, author, year, isbn):
conn, cursor = init_db()
print("issue book")
title = title.get()
author = author.get()
year = year.get()
isbn = isbn.get()
code=issue_book(cursor,title,author,year,isbn)
if code==-1:
messagebox.showerror("Undefined", "this function is not yet defined!")
messagebox.showinfo("book issued")
conn.commit()
conn.close()
print("book issued")

def delete_book(title, author, year, isbn):
conn, cursor = init_db()
print("delte book")
title = title.get()
author = author.get()
year = year.get()
isbn = isbn.get()
code = remove_from_table(cursor, title, author, year, isbn)
if code==-1:
messagebox.showerror("Error!", "something went wrong!")
messagebox.showinfo("Deleted!", f"Deleted the book: {title}, {author}, {year}, {isbn}")
conn.commit()
conn.close()
print("book deleted")

from tkinter import *
from tkinter import ttk
from tkinter import messagebox

def gui():

root = Tk()
root.title("LBMS | Library Book Management System")

title = StringVar()
author = StringVar()
year = StringVar()
isbn = StringVar()

title_label = Label(root, text="title:", padx=30)
author_label = Label(root, text="author:", padx=30)
year_label = Label(root, text="year:", padx=30)
isbn_label = Label(root, text="isbn:", padx=30)

title_entry = Entry(root, textvariable=title)
author_entry = Entry(root, textvariable=author)
year_entry = Entry(root, textvariable=year)
isbn_entry = Entry(root, textvariable=isbn)


scrollbar = Scrollbar(root, orient="vertical")
listArea = Listbox(root, bg='white', width=100, yscrollcommand=scrollbar.set)

list_all_btn = Button(root, text="List All", command=lambda:list_all_books(listArea))
list_all_btn.grid(row=20,column=6)
search_btn = Button(root, text="Search", command=lambda:search_book(listArea, title, author, year, isbn))
search_btn.grid(row=20,column=7)
add_btn = Button(root, text="Add", command=lambda:add_book(title, author, year, isbn))
add_btn.grid(row=20,column=8)
issue_btn = Button(root, text="Issue", command=lambda:issue_book(title, author, year, isbn))
issue_btn.grid(row=20,column=9)
del_btn = Button(root, text="delete", command=lambda:delete_book(title, author, year, isbn))
del_btn.grid(row=20,column=10)
exit_btn = Button(root, text="Exit", command=root.destroy)
exit_btn.grid(row=20,column=11)

scrollbar.config(command=listArea.yview)

title_label.grid(row=0, column=1)
author_label.grid(row=1, column=1)
year_label.grid(row=2, column=1)
isbn_label.grid(row=3, column=1)


title_entry.grid(row=0, column=2)
author_entry.grid(row=1, column=2)
year_entry.grid(row=2, column=2)
isbn_entry.grid(row=3, column=2)

listArea.grid(row=4,column=0,columnspan=9,sticky="nsnew")
scrollbar.grid(row=8, column=9, sticky="ns")

list_all_btn.grid(row=9, column=0)
search_btn.grid(row=9, column=1)
add_btn.grid(row=9, column=2)
issue_btn.grid(row=9, column=3)
del_btn.grid(row=9, column=4)
exit_btn.grid(row=9, column=7)


print("entering lbms")
root.mainloop()
print("exit")

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.