Challenge

Project 1 - English Dictionary App & Library Book Management System

import sqlite3 as sql
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as mb
import tkinter.simpledialog as sd
from tkinter import *


root=Tk()
root.title('.....Library Management Application.....')


def Database():
global conn,cursor
conn=sql.connect('simple.db')
cursor=conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS Booklibrary(Bookname TEXT,Author TEXT,Year TEXT, ISBN TEXT)')

def create():
if BOOKNAME.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 Booklibrary(Bookname,Author,Year,ISBN)VALUES(?,?,?,?)',(str(BOOKNAME.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())))
conn.commit()
BOOKNAME.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 Booklibrary ORDER BY Author 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=mb.askquestion('Do you want to Exit ?(y/n)',icon='warning')
if result == 'yes':
root.destroy()
exit()


#variables..
BOOKNAME=StringVar()
AUTHOR=StringVar()
YEAR=StringVar()
ISBN=StringVar()



#FRAMES
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=400,height=1000)
Forms.pack(side="top")

#buttons
Buttons=Frame(Left,width=300,height=100,bd=8,relief='raise')
Buttons.pack(side="bottom")

#Labels
txt_title=Label(Top,width=900,font=('arial',24),text='.....Library Management Application.....')
txt_title.pack()
txt_Bookname=Label(Forms,text='Bookname',font=('arial',16),bd=15)
txt_Bookname.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 widgets
Bookname=Entry(Forms,textvariable=BOOKNAME,width=30)
Bookname.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 widgets
btn_display=Button(Buttons,width=10,text="Display")
btn_display.pack(side="left")
btn_search=Button(Buttons,width=10,text="Search")
btn_search.pack(side="left")
btn_add=Button(Buttons,width=10,text="Add",command=create)
btn_add.pack(side="left")
btn_issue=Button(Buttons,width=10,text="Issue",command=Read)
btn_issue.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 widgets
scrollbary=Scrollbar(Right,orient=VERTICAL)
scrollbarx=Scrollbar(Left,orient=HORIZONTAL)

tree=ttk.Treeview(Right,columns=('Book','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('Book',text='Book',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=120)
tree.column('#3',stretch=NO,minwidth=0,width=160)
tree.pack()
#instaaliztion
root.mainloop()
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.