Project 1 - English Dictionary App & Library Book Management System
English Dictionary:
def display_menu():
print("""Menu:
1. Add a new word
2. Find the meaning
3. Update a word
4. Exit
Choose from the above""")
import json
d = {}
display_menu()
while True:
choice = int(input('Enter your choice:'))
if choice == 1:
word = input('Enter a word: ').title()
meaning = input('Enter its meaning: ').title()
d[word] = meaning
with open('words.txt','w') as f:
a=json.dump(d,f)
elif choice == 2:
word = input('Enter the word: ').title()
with open('words.txt','r') as f1:
m = json.load(f1)
print('Meaning of the word : ',m[word])
elif choice == 3:
word = input('Enter the word:')
upd_meaning = input('Update the meaning of the word:')
with open ('words.txt','w') as f2:
m[word] = upd_meaning
u = json.dump(m,f2)
elif choice == 4:
print('*'*20,'Exit Dictionary','*'*20)
break
else:
print('Please select from the above menu only')
LMS:
from tkinter import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox
root = Tk()
root.title('A library application')
def Database():
global conn,cursor
conn = sqlite3.connect('books.db')
cursor = conn.cursor
cursor.execute("CREATE TABLE IF NOT EXISTS member(booktitle TEXT NOTNULL, author TEXT, year TEXT, isbn PRIMARY KEY NOT NULL)")
def Add():
if Booktitle.get()=='' or Author.get()=='' or Year.get()==0 or ISBN.get()==0:
text_result.config(text="Please enter all the fields",fg='red')
dele()
else:
Database()
cursor.execute("INSERT INTO member(Booktitle,Author,Year,ISBN) VALUES(?,?,?,?)",(Booktitle.get(),Author.get(),Year.get(),ISBN.get()))
conn.commit()
Booktitle.set("")
Author.set("")
Year.set("")
ISBN.set("")
cursor.close()
dele()
conn.close()
text_result.config(text="Record Inserted !",fg="green")
def search():
tree.delete(*tree.get_children())
Database()
if ISBN.get()!=0:
cursor.execute('SELECT * FROM member WHERE ISBN=?',(ISBN.get(),))
rows=cursor.fetchall()
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
dele()
conn.close()
text_result.config(text='Successfully fetched data !',fg="black")
elif Booktitle.get()!='' and Author.get()!='' and Year.get()!=0 :
cursor.execute('SELECT * FROM member WHERE Booktitle=? AND Author=? AND Year=?',(Booktitle.get(),Author.get(),Year.get()))
rows=cursor.fetchall()
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
dele()
conn.close()
text_result.config(text='Successfully fetched data !',fg="black")
elif Booktitle.get()!='' and Author.get()!='':
cursor.execute('SELECT * FROM member WHERE Booktitle=? AND Author=? ',(Booktitle.get(),Author.get()))
rows=cursor.fetchall()
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
dele()
conn.close()
text_result.config(text='Successfully fetched data !',fg="black")
elif Author.get()!='' and Year.get()!=0:
cursor.execute('SELECT * FROM member WHERE Author=? AND Year=? ',(Author.get(),Year.get()))
rows=cursor.fetchall()
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
dele()
conn.close()
text_result.config(text='Successfully fetched data !',fg="black")
elif Booktitle.get()!='' and Year.get()!=0:
cursor.execute('SELECT * FROM member WHERE Booktitle=? AND Year=? ',(Booktitle.get(),Year.get()))
rows=cursor.fetchall()
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
dele()
conn.close()
text_result.config(text='Successfully fetched data !',fg="black")
elif Booktitle.get()!='' or Author.get()!='' or Year.get()!=0:
cursor.execute('SELECT * FROM member WHERE Booktitle=? OR Author=? OR Year=?',(Booktitle.get(),Author.get(),Year.get()))
rows=cursor.fetchall()
for data in rows:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
dele()
conn.close()
text_result.config(text='Successfully fetched data !',fg="black")
elif Booktitle.get()=='' and Author.get()=='' and Year.get()==0 and ISBN.get()==0:
text_result.config(text='Enter atleast a single Identity',fg='red')
dele()
conn.close()
def issue():
Database()
sel=tree.selection()
if len(sel)>0:
tree.delete(sel)
text_result.config(text='Successfully Issued :)',fg='green')
else:
text_result.config(text='Select a book from library',fg='black')
dele()
conn.close()
def delete():
tree.delete(*tree.get_children())
Database()
if ISBN.get()!=0:
cursor.execute('DELETE FROM member WHERE ISBN=?',(ISBN.get(),))
conn.commit()
text_result.config(text='Suceessfully Deleted :)',fg='green')
else:
text_result.config(text='Enter ISBN to delete',fg='red')
dele()
conn.close()
def dele():
e1.delete(0,END)
e2.delete(0,END)
e3.delete("0","end")
e3.insert(0,0)
e4.delete("0","end")
e4.insert(0,0)
def Display():
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM member")
fetch=cursor.fetchall()
for data in fetch:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
cursor.close()
text_result.config(text='Successfully data displayed !',fg="black")
def exit():
result=tkMessageBox.askquestion('Do you want to exit ? (Y/N)',icon='warning')
if result=='yes':
root.destroy()
root=Tk()
root.title('......Library Management Application...... ')
Top=Frame(root,width=900,height=50,bd=8,relief='raise',bg = 'BLUE')
Top.pack(side=TOP)
l=Label(Top,text='......Library Management Application...... ',font=('arial',24))
l.pack()
Left=Frame(root,width=400,height=100,bd=8,relief='raise',bg = 'RED')
Left.pack(side=LEFT)
Right=Frame(root,width=300,height=100,bd=8,relief='raise',bg = 'YELLOW')
Right.pack(side=RIGHT)
Forms=Frame(Left,width=500,height=500)
Forms.pack(side=TOP)
Buttons=Frame(Left,width=300,height=50,bd=8,relief='raise')
Buttons.pack(side=BOTTOM)
l1=Label(Forms,text='Booktitle:',font=('arial',16),bd=15)
l1.grid(row=0,column=0)
l2=Label(Forms,text='Author:',font=('arial',16),bd=15)
l2.grid(row=1,column=0)
l3=Label(Forms,text='Year:',font=('arial',16),bd=15)
l3.grid(row=2,column=0)
l4=Label(Forms,text='ISBN:',font=('arial',16),bd=15)
l4.grid(row=3,column=0)
text_result=Label(Buttons)
text_result.pack(side=TOP)
# Variable decalration
Booktitle=StringVar()
Author=StringVar()
Year=IntVar()
ISBN=IntVar()
e1=Entry(Forms,textvariable=Booktitle,width=30)
e1.grid(row=0,column=1)
e2=Entry(Forms,textvariable=Author,width=30)
e2.grid(row=1,column=1)
e3=Entry(Forms,textvariable=Year,width=30)
e3.grid(row=2,column=1)
e4=Entry(Forms,textvariable=ISBN,width=30)
e4.grid(row=3,column=1)
b1=Button(Buttons,width=10,text='Display',command=Display)
b1.pack(side=LEFT)
b2=Button(Buttons,width=10,text='Search',command=search)
b2.pack(side=LEFT)
b3=Button(Buttons,width=10,text='Add',command=Add)
b3.pack(side=LEFT)
b4=Button(Buttons,width=10,text='Issue',command=issue)
b4.pack(side=LEFT)
b5=Button(Buttons,width=10,text='Delete',command=delete)
b5.pack(side=LEFT)
b6=Button(Buttons,width=10,text='Exit',command=exit)
b6.pack(side=LEFT)
scrollbary=Scrollbar(Right,orient=VERTICAL)
scrollbarx=Scrollbar(Right,orient=HORIZONTAL)
tree=ttk.Treeview(Right,columns=("Booktitle","Author","Year","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('Booktitle',text='Booktitle',anchor=W)
tree.column('#0',stretch=NO,minwidth=0,width=0)
tree.heading('Author',text='Author',anchor=W)
tree.column('#1',stretch=NO,minwidth=0,width=200)
tree.heading('Year',text='Year',anchor=W)
tree.column('#2',stretch=NO,minwidth=0,width=150)
tree.heading('ISBN',text='ISBN',anchor=W)
tree.column('#3',stretch=NO,minwidth=0,width=80)
tree.pack()
root.mainloop()