Challenge

Project 1 - English Dictionary App & Library Book Management System

This project is very useful for me and try level my best did this project.

import os
import json

def mainmenu():

print('\nMain Menu\n')
print('1. Add a new word\n')
print('2. Find the meaning\n')
print('3. Update a word\n')
print('4. Exit\n')
x = int(input('Enter a choice: '))

if x == 1:
new_word()
mainmenu()
elif x == 2:
meaning()
mainmenu()
elif x == 3:
update()
mainmenu()
else:
exit()

def new_word():
word = input('Enter the word: ')
meaning = input('Enter the meaning: ')
if os.path.isfile('word.txt'):
f = open('word.txt','r')
temp = json.load(f)
temp[word] = meaning
f.close()

f = open('word.txt','w')
json.dump(temp,f)
f.close()
else:
f = open('word.txt','w')
dict1 = {word:meaning}
json.dump(dict1,f)
f.close()

def meaning():
with open('word.txt') as f:
x = json.load(f)
word = input('Enter a word to find its meaning : ')
for i in x:
if word in x:
print ('The synonym of',word,'is',x[word])
break
else:
print('This dictionary does not have an entry for',word)
break



def update():
y = input('Enter a word of which you want to update the meaning : ')
z = input('Enter the meaning of the word : ')
with open('word.txt') as f:
x = json.load(f)
xcopy = {**x}
for i in xcopy:
if y not in x:
print("Error: The entered word doesn't exist in the dictionary. Please try again.")
break
else:
x[y] = z
print('The updated meaning of',y,'is',z)
print(x)
f = open('word.txt','w')
json.dump(x,f)
f.close()


def exit():
print('Thank for choosing us!\n Exiting now...')
exit()



mainmenu()

======================Library Management System Application==============================

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 con,cursor
con = sqlite3.connect('books.db')
cursor = con.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS library(mem_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, bookname TEXT, author TEXT, year_of_publication INTEGER, isbn INTEGER)')
#cursor.execute('CREATE TABLE IF NOT EXISTS issued(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, bookname TEXT, author TEXT, year_of_publication INTEGER, isbn INTEGER)')

def Add():
if BOOKNAME.get()=='' or AUTHOR.get() == '' or YEAR_OF_PUBLICATION.get() == '':
txt_result.config(text='Please enter all fields',fg='red')
else:
Database()
cursor.execute('INSERT INTO library(bookname,author,year_of_publication,isbn) VALUES(?,?,?,?)',(str(BOOKNAME.get()),str(AUTHOR.get()),str(YEAR_OF_PUBLICATION.get()),str(ISBN.get())))
con.commit()
BOOKNAME.set('')
AUTHOR.set('')
YEAR_OF_PUBLICATION.set('')
ISBN.set('')
cursor.close()
con.close()
txt_result.config(text='Entry successful!',fg='green')

def Display():
tree.delete(*tree.get_children())
Database()
cursor.execute('SELECT * FROM library ORDER BY mem_id ASC')
fetch = cursor.fetchall()
for data in fetch:
tree.insert('','end',values=(data[0],data[1],data[2],data[3],data[4]))
cursor.close()
txt_result.config(text='Successfully fetched data!',fg='black')

def Search():
if BOOKNAME.get()=='' and AUTHOR.get() == '' and YEAR_OF_PUBLICATION.get() == '' and ISBN.get() == '':
txt_result.config(text='Please enter the fields',fg='red')
else:
tree.delete(*tree.get_children())
Database()
cursor.execute('SELECT * FROM library where bookname = ? or author = ? or year_of_publication = ? or isbn = ?',(BOOKNAME.get(),AUTHOR.get(),YEAR_OF_PUBLICATION.get(),ISBN.get()))
rows = cursor.fetchall()
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3],data[4]))
cursor.close()
txt_result.config(text='Successfully searched data!',fg='black')

def Issue():
if not tree.selection():
txt_result.config(text="Please select an item first", fg="red")
else:
Database()
tree.delete(*tree.get_children())
cursor.execute('INSERT INTO issued(bookname,author,year_of_publication,isbn) VALUES(?,?,?,?)',(str(BOOKNAME.get()),str(AUTHOR.get()),str(YEAR_OF_PUBLICATION.get()),str(ISBN.get())))
con.commit()
cursor.execute("SELECT * FROM `issued` ORDER BY id ASC")
fetch = cursor.fetchall()
for data in fetch:
tree.insert('', 'end', values=(data[0],data[1], data[2], data[3], data[4]))
cursor.close()
con.close()
BOOKNAME.set('')
AUTHOR.set('')
YEAR_OF_PUBLICATION.set('')
ISBN.set('')
btn_add.config(state=NORMAL)
btn_display.config(state=NORMAL)
btn_search.config(state=NORMAL)
btn_issue.config(state=NORMAL)
btn_delete.config(state=NORMAL)
txt_result.config(text="Successfully issued the book!", fg="black")

def Delete():
if not tree.selection():
txt_result.config(text="Please select an item first", fg="red")
else:
result = tkMessagebox.askquestion('Library Book Management System', 'Are you sure you want to delete this record?', icon="warning")
if result == 'yes':
curItem = tree.focus()
contents =(tree.item(curItem))
selecteditem = contents['values']
tree.delete(curItem)
Database()
cursor.execute("DELETE FROM `library` WHERE `mem_id` = %d" % selecteditem[0])
con.commit()
cursor.close()
con.close()
txt_result.config(text="Successfully deleted the data!", fg="black")

def Exit():
result = tkMessagebox.askquestion('Library Book Management System','Do you want to exit ? (y/n)',icon='warning')
if result == 'yes':
root.destroy()
exit()

# Variable Declerertion
BOOKNAME=StringVar()
AUTHOR=StringVar()
YEAR_OF_PUBLICATION=StringVar()
ISBN=StringVar()

#==============================================FRAME WIDGETS==========================================
Top=Frame(root, width=500, height=50, bd=8, relief='raise',highlightbackground='blue',highlightthickness=5)
Top.pack(side=TOP)
Left=Frame(root, width=400, height=1500, bd=15,bg='red', relief='raise',highlightbackground='red',highlightthickness=5)
Left.pack(side=LEFT)
Right=Frame(root, width=500, height=500, bd=10, relief='raise',highlightbackground='yellow',highlightthickness=5)
Right.pack(side=RIGHT)

Forms=Frame(Left,width=300,height=450)
Forms.pack(side=TOP)

Buttons=Frame(Left, width=300, height=100, bd=8, relief='raise')
Buttons.pack(side=BOTTOM)

#================================LABEL WIDGETS======================================================
txt_title=Label(Top,width=900,font=('arial',24),text='....Library Management Aplication....',highlightbackground='blue',highlightthickness=5)
txt_title.pack()
txt_booktitle=Label(Forms,text='Bookname:',font=('arial',16),bd=15)
txt_booktitle.grid(row=0,stick='e')
txt_author=Label(Forms,text='Author:',font=('arial',16),bd=15)
txt_author.grid(row=1,stick='e')
txt_year=Label(Forms,text='Year of publication:',font=('arial',16),bd=15)
txt_year.grid(row=2,stick='e')
txt_isbn=Label(Forms,text='ISBN:',font=('arial',16),bd=15)
txt_isbn.grid(row=3,stick='e')
txt_result=Label(Buttons)
txt_result.pack(side=TOP)

booktitle=Entry(Forms,textvariable=BOOKNAME,width=30,font=('arial',10))
booktitle.grid(row=0,column=1)
author=Entry(Forms,textvariable=AUTHOR,width=30,font=('arial',10))
author.grid(row=1,column=1)
year=Entry(Forms,textvariable=YEAR_OF_PUBLICATION,width=30,font=('arial',10))
year.grid(row=2,column=1)
isbn=Entry(Forms,textvariable=ISBN,width=30,font=('arial',10))
isbn.grid(row=3,column=1)

#======================================BUTTON WIDGETS=================================================
btn_display=Button(Buttons,width=10,text='Display',bg='green',command=Display)
btn_display.pack(side=LEFT)
btn_search=Button(Buttons,width=10,text='Search',bg='blue',command=Search)
btn_search.pack(side=LEFT)
btn_add=Button(Buttons,width=10,text='Add',command=Add)
btn_add.pack(side=LEFT)
btn_issue=Button(Buttons,width=10,text='Issue',command=Issue)
btn_issue.pack(side=LEFT)
btn_delete=Button(Buttons,width=10,text='Delete',bg='red',command=Delete)
btn_delete.pack(side=LEFT)
btn_exit=Button(Buttons,width=10,text='Exit',command=Exit)
btn_exit.pack(side=LEFT)

#========================================LIST WIDGETS================================================
scrollbary=Scrollbar(Right,orient=VERTICAL)
scrollbarx=Scrollbar(Right,orient=HORIZONTAL)

tree=ttk.Treeview(Right,columns=("SI","Bookname", "Author", "Year_of_publication", "ISBN"))

scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT,fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM,fill=X)
tree.heading('SI',text='SI',anchor=W)
tree.heading('Bookname',text='Bookname',anchor=W)
tree.heading('Author',text='Author',anchor=W)
tree.heading('Year_of_publication',text='Year_of_publication',anchor=W)
tree.heading('ISBN',text='ISBN',anchor=W)
tree.column('#0',stretch=NO,minwidth=0,width=0)
tree.column('#1',stretch=NO,minwidth=0,width=50)
tree.column('#2',stretch=NO,minwidth=0,width=200)
tree.column('#3',stretch=NO,minwidth=0,width=150)
tree.column('#4',stretch=NO,minwidth=0,width=120)
tree.pack()

#========================================INTILAZATION=================================================
if __name__=='__main__':
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.