Challenge

Project 1 - English Dictionary App & Library Book Management System

LIBRARYMANAGEMENT

import tkinter
from tkinter import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox


root = Tk()
root.title("A Library Application!")

BOOKTITLE = StringVar()
AUTHOR = StringVar()
YEAR = IntVar()
ISBN = IntVar()

def Database():
global conn, cursor
conn = sqlite3.connect('lib.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS book (Booktitle TEXT, Author TEXT, Year INTEGER, ISBN INTEGER)")

def Add():
if BOOKTITLE.get() == '' or AUTHOR.get() == '' or YEAR.get() == '' or ISBN.get() == '':
txt_result.config(text = 'Please enter all fields')
else:
Database()
cursor.execute("INSERT INTO book (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 Display():
tree.delete(*tree.get_children())
Database()
cursor.execute('SELECT * FROM book')
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 the book data!', fg = 'green')

def Search():
tree.delete(*tree.get_children())
Database()
cursor.execute('SELECT * FROM book')
fetch = cursor.fetchall()
conn2 = sqlite3.connect('lib.db')
cursor2 = conn2.cursor()

for data in fetch:

if BOOKTITLE.get() == data[0]:
if AUTHOR.get() == data[1]:
if YEAR.get() == data[2]:
if ISBN.get() == data[3]:
cursor2.execute('SELECT * FROM book WHERE Booktitle = ? or Author = ? or Year = ? or ISBN = ?', (data[0], data[1], data[2], data[3]))
else:
cursor2.execute('SELECT * FROM book WHERE Booktitle = ? or Author = ? or Year = ?', (data[0], data[1], data[2]))
else:
cursor2.execute('SELECT * FROM book WHERE Booktitle = ? or Author = ?',(data[0], data[1]))

else:
cursor2.execute('SELECT * FROM book WHERE Booktitle = ?', (data[0],))

fetch2 = cursor2.fetchall()
for data2 in fetch2:
tree.insert('','end', values = (data2[0], data2[1], data2[2], data2[3]))
cursor2.close()
cursor.close()
txt_result.config(text = "Search Results found!!", fg = 'blue')
break

elif AUTHOR.get() == data[1]:
if YEAR.get() == data[2]:
if ISBN.get() == data[3]:
cursor2.execute('SELECT * FROM book WHERE Author = ? or Year = ? or ISBN = ?',(data[1],data[2],data[3]))
else:
cursor2.execute('SELECT * FROM book WHERE Author = ? or Year = ?',(data[1], data[2]))
else:
cursor2.execute('SELECT * FROM book WHERE Author = ?',(data[1],))

fetch2 = cursor2.fetchall()
for data2 in fetch2:
tree.insert('','end', values = (data2[0], data2[1], data2[2], data2[3]))
cursor2.close()
cursor.close()
txt_result.config(text = "Search Results found!!", fg = 'blue')
break

elif YEAR.get() == data[2]:
if ISBN.get() == data[3]:
cursor2.execute('SELECT * FROM book WHERE Year = ? or ISBN = ?', (data[2],data[3]))
else:
cursor2.execute('SELECT * FROM book WHERE Year = ?',(data[2],))

fetch2 = cursor2.fetchall()
for data2 in fetch2:
tree.insert('','end', values = (data2[0], data2[1], data2[2],data2[3]))
cursor2.close()
cursor.close()
txt_result.config(text = 'Search results found!!', fg = 'blue')
break

elif ISBN.get() == data[3]:
cursor2.execute('SELECT * FROM book WHERE ISBN = ?',(data[3],))

fetch2 = cursor2.fetchall()
for data2 in fetch2:
tree.insert('','end', values = (data2[0], data2[1], data2[2],data2[3]))
cursor2.close()
cursor.close()
txt_result.config(text = 'Search results found!!', fg = 'blue')
break

else:
txt_result.config(text = 'Search results not found!!!', fg = 'red')

def Delete():
Database()
count = 0
cursor.execute('SELECT * FROM book')
fetch = cursor.fetchall()
for data in fetch:
if BOOKTITLE.get() == data[0] and AUTHOR.get() == data[1] and YEAR.get() == data[2] and ISBN.get() == data[3]:
cursor.execute('DELETE FROM book WHERE Booktitle = ? and Author = ? and Year = ? and ISBN = ?',(BOOKTITLE.get(),AUTHOR.get(),YEAR.get(),ISBN.get()))
conn.commit()
conn.close()
count += 1
txt_result.config(text = 'Book record Deleted!', fg = 'blue')

if count == 0:
cursor.close()
txt_result.config(text = 'Deletion not possible, because of the given book data incomplete or not matched!!', fg = 'red')

def Exit():
res = tkMessageBox.askquestion('Do you want to exit?', icon = 'warning')
if res == 'yes':
root.destroy()

def Issue():
pass


# Frame

Top = Frame(root,width=900,height=50,bd=8,relief='raise',bg = 'Blue')
Top.pack(side = TOP)
Left = Frame(root,width = 300,height=500,bd= 8,relief='raise',bg = 'Red')
Left.pack(side = LEFT)
Right = Frame(root,width = 600,height=500,bd= 8,relief='raise',bg = 'Yellow')
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

txt_title = Label(Top,width=900,font=('arial', 24),text = ".....Library Management Application.....")
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

_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)


# 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 = Add)
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)


scrollybary = Scrollbar(Right,orient = VERTICAL)
scrollybarx = Scrollbar(Right,orient = HORIZONTAL)

tree = ttk.Treeview(Right, columns = ('Booktitle','Author','Year','ISBN'))
scrollybary.config(command=tree.yview)
scrollybary.pack(side=RIGHT,fill=Y)
scrollybarx.config(command=tree.xview)
scrollybarx.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 = 180)
tree.column('#2',stretch = NO,minwidth = 0,width = 180)
tree.column('#3',stretch = NO,minwidth = 0,width = 80)
tree.column('#4',stretch = NO,minwidth = 0,width = 80)
tree.pack()


if __name__ == '__main__':
root.mainloop()

######ENGLISH DICTIONARYAPP

import json

print('Welcome to the dictionary')
print('Please select choice')
print('1.Add a word')
print('2.Find a meaning')
print('3.Update the word')
print('4.Exit')

f = open('words.txt','w')
call_words = {}
json.dump(call_words,f)
f.close()

while True:
n=int(input('Enter the choice:'))
if n == 1:
import json
f = open('words.txt','w')
word = input('Enter the word :')
meaning = input('Enter its meaning:')
call_words[word] = meaning
json.dump(call_words,f)
f.close()
elif n == 2:
import json
f = open('words.txt','r+')
dic = json.load(f)
find = input('Enter the word to find:')
if find in call_words:
print('The meaning is',call_words.get(find))
else:
print('Sorry the word is not found')
json.dump(call_words,f)
f.close()
elif n == 3:
import json
f = open('words.txt','w')
word1=input('Enter the word :')
update_meaning = input('Enter the updated meaning:')
call_words[word1] = update_meaning
json.dump(call_words,f)
f.close()
elif n == 4:
print('Thankyou for choosing Dictionary app')
break
else:
print('Plese enter the mentioned choice')
print('1.Add a word')
print('2.Find a meaning')
print('3.Update the word')
print('4.Exit')

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.