Challenge

Project 1 - English Dictionary App & Library Book Management System

1A: English Dictionary App

import json

print("Welcome to Dictionary app")
print("Please select your choice")
print("1. Add a word")
print("2. Find the meaning")
print("3. Update the word")
print("4. Exit")

f = open('word.txt','w')
coll_words = {}
json.dump(coll_words,f)
f.close()

while True:
n=int(input('Enter the choice:'))
if n==1:
import json
f = open('word.txt','w')
word= input('Enter the word:')
meaning=input('enter its meaning :')
coll_words[word] = meaning
json.dump(coll_words,f)
f.close()
elif n==2:
import json
f= open('word.txt','r+')
dic = json.load(f)
find=input('Enter the word to find the input:')
if find in coll_words:
print('The meaning is ', coll_words.get(find))

else:
print('The word is not found sorry!!!')
json.dump(coll_words,f)
f.close()

elif n==3:
import json
f=open('word.txt','w')
word1=input('Enter the word :')
update_meaning=input('Enter the updated meaning')
coll_words[word1] = update_meaning
json.dump(coll_words,f)
f.close()
elif n==4:
print('Thank yo for choosing the dictionary app')
break
else:
print("Please select your choice")
print("1. Add a word")
print("2. Find the meaning")
print("3. Update the word")
print("4. Exit")

Library Book Management System


from tkinter import*
import sqlite3
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessagebox
from PIL import ImageTk

window = tk.Tk()
window.geometry('900x400')
window.config(bg='white')
window.title('Library management application')


#Frames

frame_top=Frame(window,width=900,height=50,bd=8,relief='raise')
frame_top.pack(side=TOP)

frame1=Frame(window,width=300,height=500,bd=8,relief='raise')
frame1.pack(side=LEFT)

frame2=Frame(window,width=600,height=500,bd=8,relief='raise')
frame2.pack(side=RIGHT)

#Labels

title=Label(frame_top,text='Library management application',font=('arial',20,'bold'))
title.pack()

Booknames = Label(frame1, text='Book Title', font=('arial',20,'bold'))
Booknames.grid(row=0,column=0)

Authors = Label(frame1, text='Author', font=('arial',20,'bold'))
Authors.grid(row=1,column=0)

Years = Label(frame1, text='Year', font=('arial',20,'bold'))
Years.grid(row=2,column=0)

ISMBS = Label(frame1, text='ISBN', font=('arial',20,'bold'))
ISMBS.grid(row=3,column=0)


# Entry


Bookname =Text(frame1, height=2, width = 40)
Bookname.grid(row=0, column=1)

Author =Text(frame1, height=2, width = 40)
Author.grid(row=1, column=1)

Year =Text(frame1, height=2, width =40)
Year.grid(row=2, column=1)

ISBM =Text(frame1,height=2, width = 40)
ISBM.grid(row=3, column=1)

# Function

def DataBase():
global conn, cursor
con = sqlite3.connect('data1.db')
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS library (Bookname TEXT, Author TEXT, Year TEXT, ISBM TEXT)")
con.commit()
con.close()

DataBase()

def Add():
con = sqlite3.connect('data1.db')
cur = con.cursor()
if Author.get(1.0,'end-1c')!='' and Bookname.get(1.0,'end-1c')!='' and Year.get(1.0,'end-1c')!='' and ISBM.get(1.0,'end-1c')!='':
cur.execute("INSERT into library VALUES (?,?,?,?)",(Bookname.get(1.0,'end-1c'),Author.get(1.0,'end-1c'),Year.get(1.0,'end-1c'),ISBM.get(1.0,'end-1c')))
con.commit()
con.close()

def View():
present.delete(*present.get_children())
con = sqlite3.connect('data1.db')
cur = con.cursor()
cur.execute("SELECT * FROM library order by Bookname asc")
rows=cur.fetchall()
for i in rows:
present.insert('','end',values=(i[0],i[1],i[2],i[3]))
con.commit()
con.close()

def DeleteBook():
con = sqlite3.connect('data1.db')
cur = con.cursor()
cur.execute("DELETE FROM library WHERE Bookname=? and Author= ? and Year= ? and ISBM= ?",(Bookname.get(1.0,'end-1c'),Author.get(1.0,'end-1c'),Year.get(1.0,'end-1c'),ISBM.get(1.0,'end-1c')))
con.commit()
con.close()

def SearchData():
con = sqlite3.connect('data1.db')
cur = con.cursor()
cur.execute("SELECT * FROM library where Bookname=? and Author=? and Year=? and ISBM=?",(Bookname.get(1.0,'end-1c'),Author.get(1.0,'end-1c'),Year.get(1.0,'end-1c'),ISBM.get(1.0,'end-1c')))
rows=cur.fetchall()
for i in rows:
present.insert('','end',values=(i[0],i[1],i[2],i[3]))
con.commit()
con.close()

def Update():
con = sqlite3.connect('data1.db')
cur = con.cursor()
selected_items=present.selection()
if len(selected_items)>0:
present.delete(selected_items)
con.close()

def Exit():
window.destroy()


# Buttons

Display= Button(frame1, text ="Display", font = ('arial',15,'bold'), height =1, width=12, bd=4, command=View)
Display.grid(row=5,column=0)

Search = Button(frame1, text ="Search Book", font = ('arial',15,'bold'), height =1, width=12, bd=4, command= SearchData)
Search.grid(row=5,column=1)

Add = Button(frame1, text ="Add", font = ('arial',15,'bold'), height =1, width=12, bd=4, command=Add)
Add.grid(row=6,column=0)

Issue = Button(frame1, text ="Issue book", font = ('arial',15,'bold'), height =1, width=12, bd=4, command=Update)
Issue.grid(row=6,column=1)

Delete = Button(frame1, text ="Delete", font = ('arial',15,'bold'), height =1, width=12, bd=4, command=DeleteBook)
Delete.grid(row=7,column=0)

Exit = Button(frame1, text ="Exit", font = ('arial',15,'bold'), height =1, width=12, bd=4, command=Exit)
Exit.grid(row=7,column=1)

scrollbary=Scrollbar(frame2,orient=VERTICAL)
scrollbarx=Scrollbar(frame2,orient=HORIZONTAL)

present=ttk.Treeview(frame2)
scrollbary.config(command=present.yview)
scrollbary.pack(side=RIGHT,fill=Y)

scrollbarx.config(command=present.xview)
scrollbarx.pack(side=BOTTOM,fill=X)

present['column']=("Bookname","Author","Year","ISBM")
present.column('#0',width=0,stretch=NO)
present.column("Bookname",anchor=CENTER,width=100)
present.column("Author",anchor=CENTER,width=100)
present.column("Year",anchor=CENTER,width=100)
present.column("ISBM",anchor=CENTER,width=100)

present.heading('#0',text="",anchor=CENTER)
present.heading('Bookname',text="Bookname",anchor=CENTER)
present.heading('Author',text="Author",anchor=CENTER)
present.heading('Year',text="Year",anchor=CENTER)
present.heading('ISBM',text="ISBM",anchor=CENTER)

present.pack()
window.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.

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.