Challenge

Project 1 - English Dictionary App & Library Book Management System

## 1A: English Dictionary App

import json

add={}

print('Main Menu:')

print('1.Add a new word \n2.Find the meaning \n3.Update a word \n4.Exit')

while True:

try:

action=int(input('Select a given main menu bar'))

except ValueError :

print('Select integer value only')

print('-'*50)

else:

if action==1:

word=input('Enter a word in small letter').lower()

meaning=input('Enter a meaning').lower()

add[word]=meaning

with open('words.txt','w') as f:

json.dump(add,f)

#f.write('\n')

f.close()

print('word successfully added')

print('-'*50)

elif action==2:

find=input('enter a word in small letter').lower()

with open('words.txt','r') as f:

mydict=json.load(f)

if find in mydict:

print(f'Meaning of the word you entered is : {mydict[find]}')

print('-'*50)

continue

else:

print('word not found')

print('-'*50)

elif action==3:

word=input('Enter a word in small letter').lower()

with open('words.txt','r') as f:

mydict=json.load(f)

if word in mydict:

print('word :',word,'old meaning :',mydict[word])

mean=mydict[word]

with open('words.txt','r') as f:

data=f.read()

if mean in data:

newmean=input('Enter a new meaning in small letter').lower()

data=data.replace(mean,newmean)

with open('words.txt','w') as f:

f.write(data)

print('successfully updated')

print('-'*50)

elif action==4:

enter=input('Are you sure you want to exit?(yes/no):').lower()

if enter=='Yes' or enter=='yes':

print('Thank you')

print('-'*50)

break

else:

continue

else:

print('Please select correct option from the Mainmenu')

print('-'*50)

##1B: Library Book Management System

## initializing

from tkinter import *

import sqlite3

import tkinter.ttk as ttk

import tkinter.messagebox as tkMessageBox

root=Tk()

root.title("Library Book Management System")

def Database():

global conn, cursor

conn=sqlite3.connect('library1.db')

cursor=conn.cursor()

cursor.execute("CREATE TABLE IF NOT EXISTS library(Bookname TEXT,Author TEXT,Year INT, Isbn INT PRIMARY KEY)")

## Create

def Create():

Database()

conn=sqlite3.connect('library1.db')

cursor=conn.cursor()

if BOOKNAME.get()=="" or AUTHOR.get()=="" or YEAR.get()=="" or ISBN.get()=="":

label_status.config(text="please enter all the field",fg="red")

else:

label_status.config(text="Record Inserted !",fg="green")

cursor.execute("INSERT INTO library(Bookname,Author,Year,Isbn ) VALUES (?,?,?,?)",(str(BOOKNAME.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())))

BOOKNAME.set("")

AUTHOR.set("")

YEAR.set("")

ISBN.set("")

conn.commit()

conn.close()

## display

def displaybook():

book.delete(*book.get_children())

Database()

cursor.execute("SELECT * FROM library order by Bookname asc")

fetch=cursor.fetchall()

for data in fetch:

book.insert('','end',values=(data[0],data[1],data[2],data[3]))

conn.commit()

conn.close()

label_status.config(text="Successfully fetched data !",fg="black")

## Exit the program

def Exit():

root.destroy()

## delete data

def delete():

book.delete(*book.get_children())

Database()

cursor.execute("DELETE FROM library WHERE Isbn= ?",(ISBN.get() ,))

conn.commit()

conn.close()

BOOKNAME.set("")

AUTHOR.set("")

YEAR.set("")

ISBN.set("")

label_status.config(text="use isbn no. to Delete a book from the record ",fg="black")

## read the data

def searchbook():

Database()

cursor.execute('SELECT * FROM library WHERE Bookname=? OR Author=? OR Year=? OR Isbn=?',(str(BOOKNAME.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())))

fetch=cursor.fetchall()

BOOKNAME.set("")

AUTHOR.set("")

YEAR.set("")

ISBN.set("")

for data in fetch:

book.insert('','end',values=(data[0],data[1],data[2],data[3]))

conn.commit()

conn.close()

def issue():

label_status.config(text = "use isbn no to delete a record ")

###

#FRAMES

frame1= Frame(root ,width = 900 ,height = 70 ,relief = "raise",bg = "blue",padx=10)

frame1.grid(column=0,row = 0,columnspan = 2)

gap =Frame(root ,width = 50 ,height = 5 )

gap.grid(column=0,row = 1,columnspan = 2)

frame2 = Frame(root ,width = 500 ,height = 400 ,padx=10,relief = "raise",bg = "red")

frame2.grid(row = 2,column=0)

frame3 = Frame(root ,width = 500 ,height = 270,relief = "raise",bg = "yellow"

,padx=3)

frame3.grid(row = 2,column=1 , rowspan= 2)

#buttons

button = Frame(root ,width = 350 ,height = 60 ,relief = "raise",bd = 0)

button.grid(row = 3 ,column=0 )

#Labels

frame1 = Frame(root ,width = 800 ,height = 70 ,relief = "raise",bg = "blue",padx=10)

frame1.grid(column=0,row = 0,columnspan = 2)

gap =Frame(root ,width = 50 ,height = 5 )

gap.grid(column=0,row = 1,columnspan = 2)

frame2 = Frame(root ,width = 500 ,height = 400 ,padx=10,relief = "raise",bd = 1)

frame2.grid(row = 2,column=0)

frame3 = Frame(root ,width = 450 ,height = 250,relief = "raise",bg = "yellow"

,padx=3)

frame3.grid(row = 2,column=1 , rowspan= 2)

button = Frame(root ,width = 350 ,height = 60 ,relief = "raise",bd = 0)

button.grid(row = 3 ,column=0 )

heading = Label(frame1,text = "....Library Book Management System....",

font = ('arial',20 ), padx = 15,pady = 15,justify=CENTER

).grid(row = 0, column = 0)

bookname = Label(frame2 ,text = "Booktitle "

,pady = 10,font = ('arial',20),justify=LEFT

)

bookname.grid(row = 0,column = 0)

author = Label(frame2 ,text = "Author "

,pady = 10,font = ('arial',20 ),justify=LEFT

)

author.grid(row = 1,column = 0)

year = Label(frame2 ,text = "Year"

,pady = 10,font = ('arial',20 ),justify=LEFT

)

year.grid(row = 2,column = 0)

isbn = Label(frame2 ,text = "ISBN "

,pady = 10,font = ('arial',20 ),justify=LEFT

)

isbn.grid(row = 3,column = 0)

label_status = Label(root,text = "you search and delete record by isbn no",relief="raise",bd = 1)

label_status.grid(row = 5 ,column = 0,columnspan=2,pady=10)

#Entry widgets

BOOKNAME=StringVar()

AUTHOR=StringVar()

YEAR=StringVar()

ISBN=StringVar()

ebookname = Entry(frame2 ,textvariable=BOOKNAME ,width = 50

)

ebookname.grid(row= 0,column = 1)

eauthor = Entry(frame2 ,textvariable=AUTHOR ,width = 50

)

eauthor.grid(row= 1,column = 1)

eyear = Entry(frame2 ,textvariable=YEAR,width = 50

)

eyear.grid(row= 2,column = 1)

eisbn = Entry(frame2 ,textvariable=ISBN ,width = 50

)

eisbn.grid(row= 3,column = 1)

#Button widgets

display = Button(button ,width = 7 ,command = displaybook,padx = 10,relief= "raise"

,text = "Display",bd = 2).grid(row = 0 ,column = 1,padx = 10 ,pady = 10)

search = Button(button ,width = 7 ,command = searchbook,padx = 10,relief= "raise"

,text = "Search",bd = 2).grid(row = 0 ,column = 2,padx = 10 ,pady = 10)

add = Button(button,width = 7 ,command = Create ,padx = 10,relief= "raise"

,text = "Add",bd = 2).grid(row = 0 ,column = 3,padx = 10 ,pady = 10)

issue = Button(button ,width = 7 ,command = issue,padx = 15,relief= "raise",bg = "blue"

,text = "help",bd = 3).grid(row = 0 ,column = 4,padx = 10 ,pady = 10)

delete = Button(button,width = 7 ,command = delete,padx = 10,relief= "raise"

,text = "Delete",bg = "red").grid(row = 0 ,column = 5,padx = 10 ,pady = 10)

exit = Button(button ,width = 7 ,command = Exit,padx = 10,relief= "raise"

,text = "Exit",bd = 2).grid(row = 0 ,column = 6,padx = 10 ,pady = 10)

book = ttk.Treeview(frame3,height= 11)

book["column"] = ("Bookname","Author","Year","Isbn")

book.column('#0',width=0,stretch=NO)

book.column("Bookname",anchor = CENTER ,width = 120)

book.column("Author",anchor = CENTER ,width = 120)

book.column("Year",anchor = CENTER ,width = 120)

book.column("Isbn",anchor = CENTER ,width = 120)

book.heading('#0',text="",anchor=CENTER)

book.heading('Bookname',text="Bookname",anchor=CENTER)

book.heading('Author',text="Author",anchor=CENTER)

book.heading('Year',text="Year",anchor=CENTER)

book.heading('Isbn',text="Isbn(Unique)",anchor=CENTER)

book.pack()

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.