Project 1 - English Dictionary App & Library Book Management System
1A answer
from tkinter import *
from PyDictionary import PyDictionary
import json
window=Tk()
window.geometry('250x200')
def add():
file = open("words.txt","w")
word=entry.get()
file.write(word)
file.close()
def find_meaning():
word=entry.get()
dictionary=PyDictionary(word)
meaning=dictionary.printMeanings()
print(meaning)
print(type(meaning))
def update():
file = open('words.txt',"w")
word=entry.get()
json.dump(word,file)
file.close()
entry=Entry(window,font=("times",15,"bold"))
entry.grid(row=2,column=2)
b1=Button(window,text="Add a new word",command=add)
b1.grid(row=4,column=2)
b2=Button(window,text="Find meaning",command=find_meaning)
b2.grid(row=6,column=2)
b3=Button(window,text="UPDATE",command=update)
b3.grid(row=8,column=2)
b4=Button(window,text="Exit",command=window.destroy)
b4.grid(row=10,column=2)
window.mainloop()
1B Answer
import sqlite3
def create_table():
con=sqlite3.connect('mybooks.db')
cur=con.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS books(bid VARCHAR(20) primary key,title VARCHAR(30), author VARCHAR(30), year VARCHAR(4))')
con.commit()
con.close()
create_table()
from tkinter import *
from tkinter import messagebox
import sqlite3
def bookRegister():
bid = bookInfo1.get()
title = bookInfo2.get()
author = bookInfo3.get()
year = bookInfo4.get()
insertBooks = "insert into "+bookTable+" values('"+bid+"','"+title+"','"+author+"','"+year+"')"
try:
cur.execute(insertBooks)
con.commit()
messagebox.showinfo('Success',"Book added successfully")
except:
messagebox.showinfo("Error","Can't add data into Database")
print(bid)
print(title)
print(author)
print(year)
window.destroy()
def addBook():
global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,window
window = Tk()
window.title("Library")
window.minsize(width=400,height=400)
window.geometry("600x500")
mypass = "window"
mydatabase="db"
con = sqlite3.connect('mybooks.db')
cur = con.cursor()
bookTable = "books"
Canvas1 = Canvas(window)
Canvas1.config(bg="#ff6e40")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(window,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="Add Books", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(window,bg='black')
labelFrame.place(relx=0.1,rely=0.4,relwidth=0.8,relheight=0.4)
lb1 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
lb1.place(relx=0.05,rely=0.2, relheight=0.08)
bookInfo1 = Entry(labelFrame)
bookInfo1.place(relx=0.3,rely=0.2, relwidth=0.62, relheight=0.08)
lb2 = Label(labelFrame,text="Title : ", bg='black', fg='white')
lb2.place(relx=0.05,rely=0.35, relheight=0.08)
bookInfo2 = Entry(labelFrame)
bookInfo2.place(relx=0.3,rely=0.35, relwidth=0.62, relheight=0.08)
lb3 = Label(labelFrame,text="Author : ", bg='black', fg='white')
lb3.place(relx=0.05,rely=0.50, relheight=0.08)
bookInfo3 = Entry(labelFrame)
bookInfo3.place(relx=0.3,rely=0.50, relwidth=0.62, relheight=0.08)
lb4 = Label(labelFrame,text="Year : ", bg='black', fg='white')
lb4.place(relx=0.05,rely=0.65, relheight=0.08)
bookInfo4 = Entry(labelFrame)
bookInfo4.place(relx=0.3,rely=0.65, relwidth=0.62, relheight=0.08)
SubmitBtn = Button(window,text="SUBMIT",bg='#d1ccc0', fg='black',command=bookRegister)
SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
quitBtn = Button(window,text="Quit",bg='#f7f1e3', fg='black', command=window.destroy)
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
window.mainloop()
from tkinter import *
from tkinter import messagebox
import sqlite3
mypass = "window"
mydatabase="db"
con = sqlite3.connect('mybooks.db')
cur = con.cursor()
bookTable = "books"
def View():
window = Tk()
window.title("Library")
window.minsize(width=400,height=400)
window.geometry("600x500")
Canvas1 = Canvas(window)
Canvas1.config(bg="#12a4d9")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(window,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="View Books", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(window,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
y = 0.25
Label(labelFrame, text="%-10s%-40s%-30s%-20s"%('BID','Title','Author','Status'),bg='black',fg='white').place(relx=0.07,rely=0.1)
Label(labelFrame, text="----------------------------------------------------------------------------",bg='black',fg='white').place(relx=0.05,rely=0.2)
getBooks = "select * from "+bookTable
try:
cur.execute(getBooks)
con.commit()
for i in cur:
Label(labelFrame, text="%-10s%-30s%-30s%-20s"%(i[0],i[1],i[2],i[3]),bg='black',fg='white').place(relx=0.07,rely=y)
y += 0.1
except:
messagebox.showinfo("Failed to fetch files from database")
quitBtn = Button(window,text="Quit",bg='#f7f1e3', fg='black', command=window.destroy)
quitBtn.place(relx=0.4,rely=0.9, relwidth=0.18,relheight=0.08)
window.mainloop()
from tkinter import *
from tkinter import messagebox
import sqlite3
mypass = "window"
mydatabase="db"
con = sqlite3.connect('mybooks.db')
cur = con.cursor()
bookTable = "books"
def deleteBook():
bid = bookInfo1.get()
deleteSql = "delete from "+bookTable+" where bid = '"+bid+"'"
try:
cur.execute(deleteSql)
con.commit()
messagebox.showinfo('Success',"Book Record Deleted Successfully")
except:
messagebox.showinfo("Please check Book ID")
print(bid)
bookInfo1.delete(0, END)
window.destroy()
def delete():
global bookInfo1,bookInfo2,bookInfo3,bookInfo4,Canvas1,con,cur,bookTable,window
window = Tk()
window.title("Library")
window.minsize(width=400,height=400)
window.geometry("600x500")
Canvas1 = Canvas(window)
Canvas1.config(bg="#006B38")
Canvas1.pack(expand=True,fill=BOTH)
headingFrame1 = Frame(window,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.25,rely=0.1,relwidth=0.5,relheight=0.13)
headingLabel = Label(headingFrame1, text="Delete Book", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
labelFrame = Frame(window,bg='black')
labelFrame.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.5)
lb2 = Label(labelFrame,text="Book ID : ", bg='black', fg='white')
lb2.place(relx=0.05,rely=0.5)
bookInfo1 = Entry(labelFrame)
bookInfo1.place(relx=0.3,rely=0.5, relwidth=0.62)
SubmitBtn = Button(window,text="SUBMIT",bg='#d1ccc0', fg='black',command=deleteBook)
SubmitBtn.place(relx=0.28,rely=0.9, relwidth=0.18,relheight=0.08)
quitBtn = Button(window,text="Quit",bg='#f7f1e3', fg='black', command=window.destroy)
quitBtn.place(relx=0.53,rely=0.9, relwidth=0.18,relheight=0.08)
window.mainloop()
window =Tk()
window.title("Library")
window.minsize(width=400,height=400)
window.geometry("600x500")
from tkinter import *
from tkinter import messagebox
import sqlite3
headingFrame1 = Frame(window,bg="#FFBB00",bd=5)
headingFrame1.place(relx=0.2,rely=0.1,relwidth=0.7,relheight=0.16)
headingLabel = Label(headingFrame1, text="Welcome to \n Library Management Application", bg='black', fg='white', font=('Courier',15))
headingLabel.place(relx=0,rely=0, relwidth=1, relheight=1)
b1 = Button(window,text="Add Book Details",bg='black', fg='white', command=addBook)
b1.place(relx=0.28,rely=0.4, relwidth=0.45,relheight=0.1)
b2 = Button(window,text="Delete Book",bg='black', fg='white', command=delete)
b2.place(relx=0.28,rely=0.5, relwidth=0.45,relheight=0.1)
b3 = Button(window,text="View Book List",bg='black', fg='white', command=View)
b3.place(relx=0.28,rely=0.6, relwidth=0.45,relheight=0.1)
window.mainloop()