Project 1 - English Dictionary App & Library Book Management System
English Dictionary App returns definitions of the words
In [9]:
import json
choice = 1
while(choice!=4):
choice=int(input('''Main menu
press 1. to add new word
press 2. to search word
press 3. to update the word
press 4. to exit
Enter the choice: '''))
print("Your choice is: ",choice)
if (choice==2):
word=input("Enter the word you want to search: ").title()
with open('words.txt','r') as t:
a = json.load(t)
for i in a:
if (word==i):
print("Meaning of: ",word, "is: ",a[i])
break
else:
print("No word in dictionery you can try adding")
elif(choice==1):
temp={}
temp1={}
word=input("Enter the new word: ").title()
with open("words.txt",'r') as t:
a = json.load(t)
for i in a:
if(word==i):
print("Word already in dictionary try update")
break
else:
meaning = input("Enter the meaning: ").title()
temp[word]=meaning
for i in a,temp:
temp1.update(i)
with open("words.txt",'w') as f:
json.dump(temp1,f)
elif (choice==4):
print("...Exit App...")
elif(choice==3):
temp={}
temp1={}
word = input("Enter the word to update: ").title()
with open("words.txt",'r') as t:
a = json.load(t)
for i in a:
if(word==i):
meaning=input("Enter the meaning: ").title()
temp[word]=meaning
break
else:
print(word,"is not in list try adding")
for i in a,temp:
temp1.update(i)
with open("words.txt",'w') as t:
json.dump(temp1,t)
else:
print("Please choose between above options")
Main menu
press 1. to add new word
press 2. to search word
press 3. to update the word
press 4. to exit
Enter the choice: 1
Your choice is: 1
Enter the new word: soon
Enter the meaning: in a short time from now
Main menu
press 1. to add new word
press 2. to search word
press 3. to update the word
press 4. to exit
Enter the choice: 1
Your choice is: 1
Enter the new word: torch
Enter the meaning: a small electric light that you carry in your hand
Main menu
press 1. to add new word
press 2. to search word
press 3. to update the word
press 4. to exit
Enter the choice: 2
Your choice is: 2
Enter the word you want to search: torch
Meaning of: Torch is: A Small Electric Light That You Carry In Your Hand
Main menu
press 1. to add new word
press 2. to search word
press 3. to update the word
press 4. to exit
Enter the choice: 3
Your choice is: 3
Enter the word to update: torch
Enter the meaning: An electric light
Main menu
press 1. to add new word
press 2. to search word
press 3. to update the word
press 4. to exit
Enter the choice: 2
Your choice is: 2
Enter the word you want to search: torch
Meaning of: Torch is: An Electric Light
Main menu
press 1. to add new word
press 2. to search word
press 3. to update the word
press 4. to exit
Enter the choice: 4
Your choice is: 4
...Exit App...
In [ ]:
Library Book Management System
In [53]:
from tkinter import *
import sqlite3
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox
In [54]:
fullframe = Tk()
fullframe.title('A Library application')
Out[54]:
''
In [55]:
def Database():
global conn,cursor
conn=sqlite3.connect('LBMS.db')
cursor=conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS library(booktitle TEXT, author TEXT, year INTEGER,ISBN INTEGER)")
In [56]:
def displaybook():
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM library ORDER BY booktitle ASC")
fetch=cursor.fetchall()
for data in fetch:
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
cursor.close()
conn.close()
tk.messagebox.showinfo('Library','Data fetched successfully')
In [57]:
def searchbook():
titleauthor=((author.get()).title())
titlebookname=((booktitle.get()).title())
publishedyear=((year.get()).title())
titleISBN=((ISBN.get()).title())
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM library")
fetch=cursor.fetchall()
count = 0
for data in fetch:
if(titlebookname==data[0]) and (titleauthor==data[1]) and (str(year.get())==str(data[2])) and (str(ISBN.get()==str(data[3]))):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(titlebookname==data[0]):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(titleauthor==data[1]):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(str(publishedyear)==str(data[2])):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(str(titleISBN)==str(data[3])):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
if(count==0):
tk.messagebox.showinfo('Library','No book like this in library')
cursor.close()
conn.close()
author.set("")
booktitle.set("")
year.set("")
ISBN.set("")
In [58]:
def addbook():
Database()
titlebookname=((booktitle.get()).title())
titleauthor=((author.get()).title())
titlepublishedyear=str(year.get())
titleISBN=str(ISBN.get())
if ((titlebookname=='') or (titleauthor=='') or (titlepublishedyear=='') or (titleISBN=='')):
tk.messagebox.showinfo('Library','Please fill all the details')
else:
Database()
cursor.execute("INSERT INTO library(booktitle,author,year,ISBN) VALUES(?,?,?,?)",(titlebookname,titleauthor,titlepublishedyear,titleISBN))
conn.commit()
author.set("")
booktitle.set("")
year.set("")
ISBN.set("")
cursor.close()
conn.close()
tk.messagebox.showinfo('Library','values inserted')
In [59]:
def deletebook():
titleauthor=((author.get()).title())
titlebookname=((booktitle.get()).title())
titleISBN=((ISBN.get()).title())
titlepublishedyear=(year.get().title())
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM library")
fetch=cursor.fetchall()
count=0
for data in fetch:
if ((titlebookname==data[0])and (titleauthor==data[1])and (str(titleISBN==data[3]))and(str(titlepublishedyear==data[2]))):
tempa=("'"+str(titlebookname)+"'")
tempb=("'"+str(titleauthor)+"'")
tempp=("'"+str(titlepublishedyear)+"'")
tempi=("'"+str(titleISBN)+"'")
temp1="DELETE FROM library WHERE booktitle= "+tempa +"and author= "+tempb +"and year = "+tempp +"and ISBN= "+tempi
cursor.execute(temp1)
conn.commit()
count+=1
if(count==0):
tk.messagebox.showinfo('Library','No data with this name')
else:
tk.messagebox.showinfo('Library','Book deleted')
author.set("")
booktitle.set("")
year.set("")
ISBN.set("")
conn.commit()
cursor.close()
conn.close()
In [60]:
def issuebook():
titleauthor=((author.get()).title())
titlebookname=((booktitle.get()).title())
titleISBN=((ISBN.get()).title())
titlepublishedyear=(year.get().title())
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM library")
fetch=cursor.fetchall()
cursor.execute("DELETE FROM library")
count=0
for data in fetch:
if((titlebookname==data[0])and (titleauthor==data[1])and (str(titlepublishedyear==data[2]))and (str(titleISBN==data[3]))):
if(count==0):
count+=1
tk.messagebox.showinfo('Library','Book issued')
else:
cursor.execute("INSERT INTO library(booktitle,author,year,ISBN)VALUES(?,?,?,?)",(titlebookname,titleauthor,titlepublishedyear,titleISBN))
conn.commit()
else:
cursor.execute("INSERT INTO library(booktitle,author,year,ISBN)VALUES(?,?,?,?)",(titlebookname,titleauthor,titlepublishedyear,titleISBN))
conn.commit()
if(count==0):
tk.messagebox.showinfo('Library','No book with this detail in library')
author.set("")
booktitle.set("")
year.set("")
ISBN.set("")
conn.commit()
cursor.close()
conn.close()
def exit():
result=tkMessageBox.askquestion('Library','Do you want to exit (y/n)',icon='warning')
if(result=='yes'):
fullframe.destroy()
else:
tk.messagebox.showinfo('Library','You will now return to the application screen')
In [61]:
# Frame
TitleFrame=Frame(fullframe,width=900,padx=20,bd=20,relief=RIDGE,bg='grey85')
TitleFrame.pack(side=TOP)
lblTitle=Label(TitleFrame,width=35,font=('Lucida Sans',40),text='Library Managment')
lblTitle.grid()
LeftFrame=Frame(fullframe,bd=20,width=500,height=520,padx=20,relief=RIDGE,bg='red')
LeftFrame.pack(side=LEFT)
ButtonFrame=Frame(LeftFrame,bd=20,width=250,padx=20,relief=RIDGE,bg='grey85')
ButtonFrame.pack(side=BOTTOM)
Form=Frame(LeftFrame,bd=20,width=620,height=520,padx=20,bg='grey85')
Form.pack()
RightFrame=Frame(fullframe,bd=20,width=620,height=520,padx=20,relief=RIDGE,bg='yellow')
RightFrame.pack(side=RIGHT)
In [62]:
# Variable
author=StringVar()
booktitle=StringVar()
year=StringVar()
ISBN=StringVar()
In [63]:
# Label and Entry
lbl_authorname=Label(Form,text="Booktitle:",font=('Rockwell',15),fg='black')
lbl_authorname.grid(row=0,column=0,sticky='w')
entry_authorname=Entry(Form,textvariable=booktitle,width=25)
entry_authorname.grid(row=0,column=1)
lbl_bookname=Label(Form,text="Author:",font=('Rockwell',15), fg='black')
lbl_bookname.grid(row=1,column=0,sticky='w')
entry_bookname=Entry(Form,textvariable=author,width=25)
entry_bookname.grid(row=1,column=1)
lbl_publishedyear=Label(Form,text="Year:",font=('Rockwell',15),fg='black')
lbl_publishedyear.grid(row=2,column=0,sticky='w')
entry_publishedyear=Entry(Form,textvariable=year,width=25)
entry_publishedyear.grid(row=2,column=1)
lbl_ISBN=Label(Form,text="ISBN:",font=('Rockwell',15), fg='black')
lbl_ISBN.grid(row=3,column=0,sticky='w')
entry_ISBN=Entry(Form,textvariable=ISBN,width=25)
entry_ISBN.grid(row=3,column=1)
In [64]:
# Buttons
but_view=Button(ButtonFrame,text="Display",width=6,font=('Rockwell',14),command=displaybook,bg='grey85')
but_view.grid(row=1,column=0)
but_search=Button(ButtonFrame,text="Search",width=6,font=('Rockwell',14),command=searchbook,bg='grey85')
but_search.grid(row=1,column=1)
but_add=Button(ButtonFrame,text="Add",width=6,font=('Rockwell',14),command=addbook,bg='grey85')
but_add.grid(row=1,column=2)
but_issue=Button(ButtonFrame,text="Issue",width=6,font=('Rockwell',14),command=issuebook,bg='grey85')
but_issue.grid(row=1,column=3)
but_delete=Button(ButtonFrame,text="Delete",width=6,font=('Rockwell',14),command=deletebook,bg='grey85')
but_delete.grid(row=1,column=4)
but_exit=Button(ButtonFrame,text="Exit",width=6,font=('Rockwell',14),command=exit,bg='grey85')
but_exit.grid(row=1,column=5)
In [65]:
# scrollbar
scrollbary=Scrollbar(RightFrame)
scrollbarx=Scrollbar(RightFrame)
col=('Book_Name','Author_Name','Published_year','ISBN')
tree=ttk.Treeview(RightFrame,columns=col,show='headings')
scrollbary=Scrollbar(RightFrame)
scrollbary.pack(side=RIGHT,fill=Y)
scrollbarx=Scrollbar(RightFrame)
scrollbarx.pack(side=BOTTOM,fill=X)
tree.heading("Book_Name",text="Booktitle",anchor=W)
tree.heading("Author_Name",text="Author",anchor=W)
tree.heading("Published_year",text="Year",anchor=W)
tree.heading("ISBN",text="ISBN",anchor=W)
tree.column("Author_Name",minwidth=0,width=150)
tree.column("Book_Name",minwidth=0,width=150)
tree.column("Published_year",minwidth=0,width=200)
tree.column("ISBN",minwidth=0,width=150)
tree.pack(side=TOP,fill=BOTH)
fullframe.configure(bg='grey85')
fullframe.mainloop()