Challenge

Project 1 - English Dictionary App & Library Book Management System

#English Dictionary
import json
user_input = 1
f=open('words.txt','w')
f.close()
while user_input !=0:
print('Choice1 : Add a new word \n Choice2 : Find the Meaning \n Choice3 : Update a word \n Choice4 : Exit' )
user_input = int(input('Please enter the choice number : '))
if user_input == 1:
word = input('please enter the new word : ')
meaning = input('please enter the meaning of '+word+' : ')
dictionary = {word:meaning}
f=open('words.txt','w')
json.dump(dictionary,f)
f.close()
elif user_input == 2:
word = input('please enter a word to find its meaning : ')
f=open('words.txt','r')
dictionary=json.load(f)
if word in dictionary:
print ('The meaning of '+word+' is : '+dictionary[word])
else:
print('Word not found in the dictionary, if you know the meaning please add it in the dictionary')
f.close()
elif user_input == 3:
word = input('please enter the word to be updated: ')
meaning = input('please enter the new meaning of '+word+' : ')
f=open('words.txt','w')
dictionary = {word:meaning}
json.dump(dictionary,f)
f.close()
elif user_input == 4:
user_input =0

#library book management system
from tkinter import *
from tkinter import ttk
import sqlite3
window = Tk()
con=sqlite3.connect('books.db')
cursorobj = con.cursor()
cursorobj.execute("CREATE TABLE IF NOT EXISTS library(Booktitle TEXT,Author TEXT, Year INTEGER,ISBN INTEGER)")
def display_records():
con=sqlite3.connect('books.db')
cursorobj = con.cursor()
cursorobj.execute("select * from library")
rows = cursorobj.fetchall()
t1.delete(*t1.get_children())
if len(rows)>0:
for i in rows:
t1.insert("",END,values=i)
con.commit()
con.close()

def search_records():
con=sqlite3.connect('books.db')
cursorobj = con.cursor()
booktitle=e1_val.get()
author=e2_val.get()
year=e3_val.get()
isbn=e4_val.get()
if not isbn:
cursorobj.execute("select * from library where Booktitle = ? and Author = ? and Year = ?",(booktitle,author,year))
else:
cursorobj.execute("select * from library where Booktitle = ? and Author = ? and Year = ? and ISBN = ?",(booktitle,author,year,isbn))
rows = cursorobj.fetchall()
t1.delete(*t1.get_children())
for i in rows:


t1.insert("",END,values=i)
con.commit()
con.close()
def add_records():
con=sqlite3.connect('books.db')
cursorobj = con.cursor()
booktitle=e1_val.get()
author=e2_val.get()
year=e3_val.get()
isbn=e4_val.get()
cursorobj.execute("insert into library (Booktitle,Author,Year,ISBN) values (?,?,?,?)",(booktitle,author,year,isbn))
rows = cursorobj.fetchall()
t1.delete(*t1.get_children())
t1.insert("",END,values="record added successfully")
con.commit()
con.close()
# def issue_records():


def delete_records():
con=sqlite3.connect('books.db')
cursorobj = con.cursor()
booktitle=e1_val.get()
author=e2_val.get()
year=e3_val.get()
isbn=e4_val.get()
if not isbn:
cursorobj.execute("delete from library where Booktitle = ? and Author = ? and Year = ?",(booktitle,author,year))
else:
cursorobj.execute("delete from library where Booktitle = ? and Author = ? and Year = ? and ISBN = ?",(booktitle,author,year,isbn))
rows = cursorobj.fetchall()
t1.delete(*t1.get_children())
t1.insert("",END,values="record deleted successfully")
con.commit()
con.close()


l1=Label(window,text="BookTitle : ")
l1.grid(row=0,column=0)
e1_val=StringVar()
e1=Entry(window,textvariable=e1_val)
e1.grid(row=0,column=1)
l2=Label(window,text="Author : ")
l2.grid(row=1,column=0)
e2_val=StringVar()
e2=Entry(window,textvariable=e2_val)
e2.grid(row=1,column=1)
l3=Label(window,text="Year : ")
l3.grid(row=2,column=0)
e3_val=StringVar()
e3=Entry(window,textvariable=e3_val)
e3.grid(row=2,column=1)
l4=Label(window,text="ISBN : ")
l4.grid(row=3,column=0)
e4_val=StringVar()
e4=Entry(window,textvariable=e4_val)
e4.grid(row=3,column=1)
b1=Button(window, text="Display",command=display_records)
b1.grid(row=4,column=0)
b2=Button(window, text="Search",command=search_records)
b2.grid(row=4,column=1)
b3=Button(window, text="Add",command=add_records)
b3.grid(row=4,column=2)
b4=Button(window, text="Issue", state="disabled")
b4.grid(row=4,column=3)
b5=Button(window, text="Delete",command=delete_records)
b5.grid(row=4,column=4)
b6=Button(window, text="Exit",command=window.destroy)
b6.grid(row=4,column=5)
cols=('BookTitle','Author','Year','ISBN')
t1=ttk.Treeview(window,columns=cols,show='headings')
for col in cols:
t1.heading(col,text=col)
t1.grid(row=1,column=0,columnspan=2)
t1.place(x=10, y=200)
t1.grid(row = 0,column=8)
con.commit()
con.close()
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.