Project 1 - English Dictionary App & Library Book Management System
Project Name : English Dictionary App & Libray Book Management System.
1A English Dictionary App:
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.
import sys
import fileinput
from tkinter import *
import json
window=Tk()
window.geometry('250x200')
def Add_Word():
f = open('word.txt', 'a+')
word = input("Enter your word : ")
meaning = input(" Enter the Meaning of the word : ")
a = word + " : " + meaning
f.write("\n")
f.write(a)
print("data write sucsessfully!")
f.close()
def Find_Meaning():
readFile = open('word.txt', 'r')
print(readFile)
word = input("Enter word to find the meaning : ")
for i in readFile:
if word in i:
print(f'This word present in the dictionary \t " {i} " : ' )
break
readFile.close()
def update():
file = open('words.txt',"w")
word=entry.get()
json.dump(word,file)
file.close()
entry=Entry(window,font=("times",15,"bold"))
entry.grid(row=2,column=2)
b1=Button(window,text="Add a new word",command=Add_Word)
b1.grid(row=4,column=2)
b2=Button(window,text="Find meaning",command=Find_Meaning)
b2.grid(row=6,column=2)
b3=Button(window,text="UPDATE",command=update)
b3.grid(row=8,column=2)
b4=Button(window,text="Exit",command=window.destroy)
b4.grid(row=10,column=2)
window.mainloop()
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.
def create_table():
con=sqlite3.connect('mybooks.db')
cur=con.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS books(bid VARCHAR(20) primary key,title VARCHAR(30), author VARCHAR(30), year VARCHAR(4))')
con.commit()
con.close()
from tkinter import *
from tkinter import messagebox
import sqlite3
def bookRegister():
bid = bookInfo1.get()
title = bookInfo2.get()
author = bookInfo3.get()
year = bookInfo4.get()
insertBooks = "insert into "+bookTable+" values('"+bid+"','"+title+"','"+author+"','"+year+"')"
try:
cur.execute(insertBooks)
con.commit()
messagebox.showinfo('Success',"Book added successfully")
except:
messagebox.showinfo("Error","Can't add data into Database")
print(bid)
print(title)
print(author)
print(year)
window.destroy()
def addBook():
global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,window
window = Tk()
window.title("Library")
window.minsize(width=400,height=400)
window.geometry("600x500")
mypass = "window"
mydatabase="db"
con = sqlite3.connect('mybooks.db')
cur = con.cursor()
bookTable = "books"
Canvas1 = Canvas(window)
Canvas1.config(bg="#ff6e40")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(window,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="Add Books", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(window,bg='black')
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4)
lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
lb1.place(relx=0.05,rely=0.2, relheight=0.08)
bookInfo1 = Entry(labelFrame)
bookInfo1.place(relx=0.3,rely=0.2, relwidth=0.62, relheight=0.08)
lb2 = Label(labelFrame,text="Title : ", bg='black', fg='white')
lb2.place(relx=0.05,rely=0.35, relheight=0.08)
bookInfo2 = Entry(labelFrame)
bookInfo2.place(relx=0.3,rely=0.35, relwidth=0.62, relheight=0.08)
lb3 = Label(labelFrame,text="Author : ", bg='black', fg='white')
lb3.place(relx=0.05,rely=0.50, relheight=0.08)
bookInfo3 = Entry(labelFrame)
bookInfo3.place(relx=0.3,rely=0.50, relwidth=0.62, relheight=0.08)
lb4 = Label(labelFrame,text="Year : ", bg='black', fg='white')
lb4.place(relx=0.05,rely=0.65, relheight=0.08)
bookInfo4 = Entry(labelFrame)
bookInfo4.place(relx=0.3,rely=0.65, relwidth=0.62, relheight=0.08)
SubmitBtn = Button(window,text="SUBMIT",bg='#d1ccc0', fg='black',command=bookRegister)
SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
quitBtn = Button(window,text="Quit",bg='#f7f1e3', fg='black', command=window.destroy)
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
window.mainloop()
mypass = "window"
mydatabase="db"
con = sqlite3.connect('mybooks.db')
cur = con.cursor()
bookTable = "books"
def View():
window = Tk()
window.title("Library")
window.minsize(width=400,height=400)
window.geometry("600x500")
Canvas1 = Canvas(window)
Canvas1.config(bg="#12a4d9")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(window,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="View Books", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(window,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
y = 0.25
Label(labelFrame, text="%-10s%-40s%-30s%-20s"%('BID','Title','Author','Status'),bg='black',fg='white').place(relx=0.07,rely=0.1)
Label(labelFrame, text="----------------------------------------------------------------------------",bg='black',fg='white').place(relx=0.05,rely=0.2)
getBooks = "select * from "+bookTable
try:
cur.execute(getBooks)
con.commit()
for i in cur:
Label(labelFrame, text="%-10s%-30s%-30s%-20s"%(i[0],i[1],i[2],i[3]),bg='black',fg='white').place(relx=0.07,rely=y)
y += 0.1
except:
messagebox.showinfo("Failed to fetch files from database")
quitBtn = Button(window,text="Quit",bg='#f7f1e3', fg='black', command=window.destroy)
quitBtn.place(relx=0.4,rely=0.9, relwidth=0.18,relheight=0.08)
window.mainloop()
mypass = "window"
mydatabase="db"
con = sqlite3.connect('mybooks.db')
cur = con.cursor()
bookTable = "books"
def deleteBook():
bid = bookInfo1.get()
deleteSql = "delete from "+bookTable+" where bid = '"+bid+"'"
try:
cur.execute(deleteSql)
con.commit()
messagebox.showinfo('Success',"Book Record Deleted Successfully")
except:
messagebox.showinfo("Please check Book ID")
print(bid)
bookInfo1.delete(0, END)
window.destroy()
def delete():
global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,window
window = Tk()
window.title("Library")
window.minsize(width=400,height=400)
window.geometry("600x500")
Canvas1 = Canvas(window)
Canvas1.config(bg="#006B38")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(window,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="Delete Book", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(window,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
lb2 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
lb2.place(relx=0.05,rely=0.5)
bookInfo1 = Entry(labelFrame)
bookInfo1.place(relx=0.3,rely=0.5, relwidth=0.62)
SubmitBtn = Button(window,text="SUBMIT",bg='#d1ccc0', fg='black',command=deleteBook)
SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
quitBtn = Button(window,text="Quit",bg='#f7f1e3', fg='black', command=window.destroy)
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
window.mainloop()
window =Tk()
window.title("Library")
window.minsize(width=400,height=400)
window.geometry("600x500")
headingFrame1 = Frame(window,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.7,relheight=0.16)
headingLabel = Label(headingFrame1, text="Welcome to \n Library Management Application", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
b1 = Button(window,text="Add Book Details",bg='black', fg='white', command=addBook)
b1.place(relx=0.28,rely=0.4, relwidth=0.45,relheight=0.1)
b2 = Button(window,text="Delete Book",bg='black', fg='white', command=delete)
b2.place(relx=0.28,rely=0.5, relwidth=0.45,relheight=0.1)
b3 = Button(window,text="View Book List",bg='black', fg='white', command=View)
b3.place(relx=0.28,rely=0.6, relwidth=0.45,relheight=0.1)
window.mainloop()