Project 1 - English Dictionary App & Library Book Management System
Project 1A: English Dictionary App
import json
filename='word.txt'
dict1={}
def add():
w=input('enter word : ')
m=input('enter mean : ')
dict1[w]=m
with open(filename,'w') as f:
json.dump(dict1,f)
print('word is added : ')
main()
def find():
w=input('enter word : ')
with open(filename,'r') as f:
f2=json.load(f)
if w in f2.keys():
for key, value in f2.items():
if key==w:
print(key,value)
else :
print('word not finds')
main()
def update():
w=input('enter word : ')
m=input('enter mean : ')
with open(filename,'r+') as f:
f2=json.load(f)
if w in f2.keys():
f2[w]=m
json.dump(f2,f)
print('word is updated')
else :
print('word not found')
main()
def Exit():
print('End of the library')
return exit
def menu():
print('Main menu')
print('1.Add new word')
print('2.find the meaning')
print('3.Update the word')
print('4.Exit')
def main():
print('========================')
print('ENGLISH DICTIONARY APP')
print('========================')
menu()
choice=int(input('enter choice'))
if choice==1:
add()
elif choice==2:
find()
elif choice==3:
update()
elif choice==4:
Exit()
else :
print('enter valid choice')
main()
project 1B: Library Book Management System
#libraries
from tkinter import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox
#window
root=Tk()
root.maxsize(1000,2500)
root.title('library Application')
#methods
def Database():
global conn,cursor
conn=sqlite3.connect('books.db')
cursor=conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS data(Booktitle TEXT not null,Author TEXT not null,Year INTEGER not null,ISBN INTEGER,unique(BookTitle,Author,Year,ISBN))")
def Create():
if(BOOKTITLE.get()=="" or AUTHOR.get()=="" or YEAR.get()=="" or ISBN.get()=="") :
txt_result.config(text="Please enter all fields ",fg="red")
else :
Database()
cursor.execute("INSERT INTO data(Booktitle,Author,Year,ISBN) VALUES(?,?,?,?)", (str(BOOKTITLE.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())))
txt_result.config(text="data added successfully ",fg="red")
conn.commit()
BOOKTITLE.set('')
AUTHOR.set('')
YEAR.set('')
ISBN.set('')
cursor.close()
conn.close()
txt_result.config(text="Record Inserted !",fg="green")
#read data
def Display():
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM data ORDER BY Author ASC")
fetch=cursor.fetchall()
for data in fetch:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
cursor.close()
txt_result.config(text="Successfully fetched data! ",fg='black')
def delete():
Database()
if BOOKTITLE.get()=="" or AUTHOR.get()=="" or YEAR.get()=="" or ISBN.get()=="" :
txt_result.config(text="Please enter all Entries!",fg="red")
else:
val="DELETE FROM data WHERE Booktitle = '"+BOOKTITLE.get()+"' and Author= '"+AUTHOR.get()+"' and Year = '"+YEAR.get()+"' and ISBN = '" +ISBN.get()+"' "
cursor.execute(val)
conn.commit()
txt_result.config(text="Book deleted successfully!",fg='green')
conn.close()
def issue():
Database()
cursor.execute('select * from data')
row=cursor.fetchall()
for data in row:
if BOOKTITLE.get() == data[0] :
txt_result.config(text="Successfully issued ",fg='blue')
else:
txt_result.config(text="give appropiate bookname ",fg='black',bg='red')
def search():
Database()
val="SELECT * FROM data WHERE Booktitle = '"+BOOKTITLE.get()+"' and Author= '"+AUTHOR.get()+"' and Year = '"+YEAR.get()+"' and ISBN = '" +ISBN.get()+"' "
cursor.execute(val)
fetch = cursor.fetchall()
for data in fetch:
if Booktitle==data[0] and Author==data[1] and Year==data[2] and ISBN==data[3] :
txt_result.config(text="Successfully searched data! ",fg='black')
else :
txt_result.config(text="enter currect data! ",fg='black')
cursor.close()
#Exit
def Exit():
result=tkMessageBox.askquestion('Do you want to exit ?(y/n)',icon='warning')
if result=='Yes':
root.destroy()
# ====Variable declaration====
BOOKTITLE=StringVar()
AUTHOR=StringVar()
YEAR=StringVar()
ISBN=StringVar()
#====Frame=====
Mainframe=Frame(root,bg='white')
Mainframe.pack()
Top=Frame(Mainframe,width=300,height=50,bd=8,relief='raise')
Top.pack(side=TOP)
Left=Frame(Mainframe,width=200,height=100,bd=8,relief='raise',bg='red')
Left.pack(side=LEFT)
Right=Frame(Mainframe,width=200,height=100,bd=8,relief='raise',bg='yellow')
Right.pack(side=RIGHT)
Forms=Frame(Left,width=200,height=40)
Forms.pack(side=TOP)
Buttons=Frame(Left,width=300,bd=8,relief='raise')
Buttons.pack(side=BOTTOM)
#RadioGroup=Frame(Forms)
#==labels=====
txt_title =Label(Top,width=900,font=('arial',24),text="LIBRARY MANAGEMENT SYSTEM",bg='blue')
txt_title.pack()
txt_BookTitle = Label(Forms, text="BookTitle:",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:",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)
#====Entry widgets=====
Booktitle=Entry(Forms,text=BOOKTITLE,width=30)
Booktitle.grid(row=0,column=1)
Author=Entry(Forms,text=AUTHOR,width=30)
Author.grid(row=1,column=1)
#RadioGroup.grid(row=2,column=1)
year=Entry(Forms,text=YEAR,width=30)
year.grid(row=2,column=1)
isbn=Entry(Forms,text=ISBN,width=30)
isbn.grid(row=3,column=1)
#===Buttons==
btn_Display = Button(Buttons, width=10, text="Display", command=Display)
btn_Display.pack(side=LEFT)
btn_Search= Button(Buttons,width=10,text='Search', command=search)
btn_Search.pack(side=LEFT)
btn_Add = Button(Buttons, width=10, text="Add",command=Create)
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',command=delete)
btn_delete.pack(side=LEFT)
btn_exit = Button(Buttons,width=10,text='Exit',command = Exit)
btn_exit.pack(side=LEFT)
#===Listwidgets========
scrollbary=Scrollbar(Right,orient=VERTICAL)
tree=ttk.Treeview(Right,columns=("BookTitle","Author","Year","ISBN"))
scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT,fill=Y)
tree.heading('BookTitle', text="BookTitle", anchor = W)
tree.heading('Author', text="Author", anchor = W)
tree.heading('Year', text="Year", 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=80)
tree.column('#2', stretch=NO, minwidth=0, width=60)
tree.column('#3', stretch=NO, minwidth=0, width=80)
tree.column('#4', stretch=NO, minwidth=0, width=90)
tree.pack()
# =INITIALIZATION ====
if __name__=='__main__':
root.mainloop()