Project 1 - English Dictionary App & Library Book Management System
1A.English Dictionary App
#creating menu example
#GUI based dictionary
from tkinter import *
window = Tk()
window.title("Dictionary App")
window.geometry("600x400+50+50")
f = open('words.txt','w')
coll_words = {}
def addNewWord():
f = open('words.txt','w')
word = input('Enter a word : ')
meaning = input('Enter its meaning : ')
coll_words[word] = meaning
f.write(str(coll_words))
f.close()
def findTheMeaning():
f = open('words.txt','r')
#Enter a word to find the meaning
word = input('Enter a word for find its meaning')
if word in coll_words:
meaning = coll_words.get(word)
print('The meaning of the word is:',meaning)
else:
print('Given word not found in dictionary')
f.close()
def updateWord():
f = open('words.txt','w')
word = input('Enter a word to update its meaning')
if word in coll_words:
update_meaning = input('Enter the new updated meaning')
coll_words[word]=update_meaning
f.write(str(coll_words))
else:
print('Given word not found in dictionary')
f.close()
def exitMenu():
window.destroy()
#create a toplevel menu in the main window
menubar = Menu(window)
#create a pulldown menu and add it to the menu bar
filemenu = Menu(menubar)
filemenu.add_command(label='Add a new word',command=addNewWord)
filemenu.add_separator()
filemenu.add_command(label='Find the meaning',command=findTheMeaning)
filemenu.add_separator()
filemenu.add_command(label='Update a word',command=updateWord)
filemenu.add_separator()
filemenu.add_command(label='Exit',command=exitMenu)
filemenu.add_separator()
menubar.add_cascade(label='Main Menu',menu=filemenu)
window.config(menu=menubar)
window.mainloop()
Enter a word : chinna Enter its meaning : its a name Enter a word for find its meaningchinna The meaning of the word is: its a name Enter a word to update its meaningchinna Enter the new updated meaningits a person name Enter a word to update its meaningchinna Enter the new updated meaningits a person name
2A. Library Book Management System
#A simple GUI based application to impliment CURD operations
#library book management system
from tkinter import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkmessagebox
root = Tk()
root.title ('Library Book Management System')
#methods
def Database():
global conn,cursor
conn = sqlite3.connect('simple.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS books(Booktitle TEXT,Author TEXT,Year TEXT,ISBN TEXT)")
def create():
if Booktitle.get() == "" or Author.get() == "" or Year.get() == "" or ISBN.get() == "":
txt_result.config(text="please enter all the fields",fd='red')
else:
Database()
cursor.execute('INSERT INTO books(Booktitle,Author,Year,ISBN)values(?,?,?,?)',(str(Booktitle.get()),str(Author.get()),str(Year.get()),str(ISBN.get())))
conn.commit()
Booktitle.set("")
Author.set("")
Year.set("")
ISBN.set("")
cursor.close()
conn.close()
txt_result.config(text="Record Inserted!",fg='green')
def Read():
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM books 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()
txt_result.config(text="successfully fetched data",fg='black')
def Exit():
result=tkmessagebox.askquestion('Do you want to exit ? (y/n)',icon='warning')
if result == 'yes':
root.destroy()
exit()
# variabledecalration
Booktitle = StringVar()
Author = StringVar()
Year = StringVar()
ISBN = StringVar()
#frame
Top=Frame(root,width = 900,height = 50,bd = 8,relief = 'raise')
Top.pack(side = TOP)
Left=Frame(root,width = 300,height = 500,bd = 8,relief = 'raise')
Left.pack(side = LEFT)
Right=Frame(root,width = 600,height = 500,bd = 8,relief = 'raise')
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 widget
txt_title = Label(Top, width=900, font=('arial',24),text="Library Book Management System")
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 Widget
booktitle = Entry(Forms, textvariable='BOOKTITLE', width=30)
booktitle.grid(row=0, column=1)
author = Entry(Forms, textvariable='AUTHOR', width=30)
author.grid(row=1, column=1)
year = Entry(Forms, textvariable='YEAR', width=30)
year.grid(row=2, column=1)
ISBN = Entry(Forms, textvariable='ISBN', width=30)
ISBN.grid(row=3, column=1)
#Button widget
btn_create = Button(Buttons, width=10, text="Create",command=create)
btn_create.pack(side=LEFT)
btn_read = Button(Buttons, width=10, text="Read",command=Read)
btn_read.pack(side=LEFT)
btn_update = Button(Buttons, width=10, text="Update")
btn_update.pack(side=LEFT)
btn_delete = Button(Buttons, width=10, text="Delete")
btn_delete.pack(side=LEFT)
btn_exit = Button(Buttons, width=10, text="Exit",command=Exit)
btn_exit.pack(side=LEFT)
#List widget
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)
scrollbary.config(command=tree.xview)
scrollbary.pack(side=BOTTOM, fill=X)
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=100)
tree.column('#3',stretch=NO, minwidth=0, width=80)
tree.column('#4',stretch=NO, minwidth=0, width=100)
if __name__=='__main__':
root.mainloop()
tree.pack()