Challenge

Project 1 - English Dictionary App & Library Book Management System

import json
from IPython.display import clear_output



def fun():
    
    
    print('-'*25)
    print('English Dictionary App')
    print('-'*25)
    print('Main Menu')
    print('-'*25)
    print('1.Add a new word')
    print('2.Find the meaning')
    print('3.Update a Word')
    print('4.Exit')
    print('-'*25)
    n=input('Select an option:')
    print('-'*25)
    
    
    if n.isdigit():
        if int(n)==1:
            print('-'*25)
            s=input('Enter the word:')
            f3=open('words.txt','r')
            dic=json.load(f3)
            if s in dic:
                clear_output()
                print('-'*25)
                print('WORD ALREADY EXIST')
                print('**'*25)
                print('**'*25)
                fun()
            else: 
                s1=input('Enter the meaning:')
                if s[0].isalpha() and s1[0].isalpha():
                    f3=open('words.txt','r')
                    dic=json.load(f3)
                    dic[s]=s1
                    f1=open('words.txt','w')
                    json.dump(dic,f1)
                    f1.close()
                    f3.close()
                
                    clear_output()
                    print('-'*25)
                    print('SUCCESSFULLY UPDATED','(',s,'=',s1,')')
                    print('**'*25)
                    print('**'*25)
                    fun()
                    
                else:
                    clear_output()
                    print('ERROR:entered inappropriate value')
                    print('**'*25)
                    print('**'*25)
                    fun()
        

        elif int(n)==2:
            print('-'*25)
            s2=input('Enter the word:')
            f3=open('words.txt','r')
            dic=json.load(f3)
            if s2 in dic:
                clear_output()
                f1=open('words.txt','r')
                dic=json.load(f1)
                print('Word:',s2)
                print('Meaning:',dic[s2])
                f1.close()
                
                print('**'*25)
                print('**'*25)
                fun()
                
            else:
                clear_output()
                print('-'*25)
                print('WORD DOES NOT EXIST')
                print('**'*25)
                print('**'*25)
                fun()
                
    
    
        
        elif int(n)==3:
            print('-'*25)
            s3=input('Enter the Word:')
            f3=open('words.txt','r')
            dic=json.load(f3)
            if s3 not in dic:
                clear_output()
                print('-'*25)
                print('WORD DOES NOT EXIST')
                print('**'*25)
                print('**'*25)
                fun()
        
            else:
                s4=input('Enter the updated meaning:')
                if s4[0].isalpha():
                    f3=open('words.txt','w')
                    dic[s3]=s4
                    json.dump(dic,f3)
                    f3.close()
                    clear_output()
                    print('-'*25)
                    print('SUCCESSFULLY UPDATED','(',s3,'=',s4,')')
                    print('**'*25)
                    print('**'*25)
                    fun()
                else:
                    clear_output()
                    print('ERROR:entered inappropriate value')
                    print('**'*25)
                    print('**'*25)
                    fun()
        
    
        elif int(n)==4:
            print('-'*25)
            print('-----EXIT-----')
        
        elif int(n)>4:
            clear_output()
            print('-'*25)
            print('PLEASE SELECT IN THE GIVEN OPTIONS')
            print('**'*25)
            print('**'*25)
            fun()
        
        elif int(n)==0:
            clear_output()
            print('-'*25)
            print('PLEASE SELECT IN THE GIVEN OPTIONS')
            print('**'*25)
            print('**'*25)
            fun()
        
        elif int(n)<0:
            clear_output()
            print('-'*25)
            print('PLEASE SELECT IN THE GIVEN OPTIONS')
            print('**'*25)
            print('**'*25)
            fun()
        
    else:
        clear_output()
        print('-'*25)
        print('PLEASE  ENTER NUMBER')
        print('**'*25)
        print('**'*25)
        fun()
        
        
fun()        



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



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

def Add():
    if Booktitle.get()=='' or Author.get()=='' or Year.get()==0 or ISBN.get()==0:
        text_result.config(text="Please enter all the fields",fg='red')
        dele()
    
        
        
        
    else:
        Database()
        cursor.execute("INSERT INTO member(Booktitle,Author,Year,ISBN) VALUES(?,?,?,?)",(Booktitle.get(),Author.get(),Year.get(),ISBN.get()))
        conn.commit()
        Booktitle.set("")
        Author.set("")
        Year.set("")
        ISBN.set("")
        cursor.close()
        dele()
        conn.close()
        text_result.config(text="Record Inserted !",fg="green")
        
        
def search():
    tree.delete(*tree.get_children())
    Database()
    if ISBN.get()!=0:
        cursor.execute('SELECT * FROM member WHERE ISBN=?',(ISBN.get(),))
        rows=cursor.fetchall()
        for data in rows:
            tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
        dele()
        conn.close()
        text_result.config(text='Successfully fetched data !',fg="black")
    elif Booktitle.get()!='' and Author.get()!='' and Year.get()!=0 :
        cursor.execute('SELECT * FROM member WHERE Booktitle=? AND Author=? AND Year=?',(Booktitle.get(),Author.get(),Year.get()))
        rows=cursor.fetchall()
        for data in rows:
            tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
        dele()
        conn.close()
        text_result.config(text='Successfully fetched data !',fg="black")
    elif Booktitle.get()!='' and Author.get()!='':
        cursor.execute('SELECT * FROM member WHERE Booktitle=? AND Author=? ',(Booktitle.get(),Author.get()))
        rows=cursor.fetchall()
        for data in rows:
            tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
        dele()
        conn.close()
        text_result.config(text='Successfully fetched data !',fg="black")
    elif Author.get()!='' and Year.get()!=0:
        cursor.execute('SELECT * FROM member WHERE Author=? AND Year=? ',(Author.get(),Year.get()))
        rows=cursor.fetchall()
        for data in rows:
            tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
        dele()
        conn.close()
        text_result.config(text='Successfully fetched data !',fg="black")
    elif Booktitle.get()!='' and Year.get()!=0:
        cursor.execute('SELECT * FROM member WHERE Booktitle=? AND Year=? ',(Booktitle.get(),Year.get()))
        rows=cursor.fetchall()
        for data in rows:
            tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
        dele()
        conn.close()
        text_result.config(text='Successfully fetched data !',fg="black")
    elif Booktitle.get()!='' or Author.get()!='' or Year.get()!=0:
        cursor.execute('SELECT * FROM member WHERE Booktitle=? OR Author=? OR Year=?',(Booktitle.get(),Author.get(),Year.get()))
        rows=cursor.fetchall()
        for data in rows:
            tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
        dele()
        conn.close()
        text_result.config(text='Successfully fetched data !',fg="black")
    elif Booktitle.get()=='' and Author.get()=='' and Year.get()==0 and ISBN.get()==0:
        text_result.config(text='Enter atleast a single Identity',fg='red')
        dele()
        conn.close()
        
        
def issue():
    Database()
    sel=tree.selection()
    if len(sel)>0:
        tree.delete(sel)
        text_result.config(text='Successfully Issued :)',fg='green')
    else:
        text_result.config(text='Select a book from library',fg='black')
    dele()
    
    conn.close()
    
def delete():
    tree.delete(*tree.get_children())
    Database()
    if  ISBN.get()!=0:
        cursor.execute('DELETE FROM member WHERE ISBN=?',(ISBN.get(),))
        conn.commit()
        text_result.config(text='Suceessfully Deleted :)',fg='green')
    else:
        text_result.config(text='Enter ISBN to delete',fg='red')
    dele()
    conn.close()
    

    
def dele():
    e1.delete(0,END)
    e2.delete(0,END)
    e3.delete("0","end")
    e3.insert(0,0)
    e4.delete("0","end")
    e4.insert(0,0)
    

    
        
        
        
        
def Display():
    tree.delete(*tree.get_children())
    Database()
    cursor.execute("SELECT * FROM member")
    fetch=cursor.fetchall()
    for data in fetch:
        tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
    cursor.close()
    text_result.config(text='Successfully data displayed !',fg="black")
    
def exit():
    result=tkMessageBox.askquestion('Do you want to exit ? (Y/N)',icon='warning')
    if result=='yes':
        root.destroy()
        
        
    
        
        
        
In [364]:
root=Tk()
root.title('......Library Management Application...... ')







Top=Frame(root,width=900,height=50,bd=8,relief='raise')
Top.pack(side=TOP)
l=Label(Top,text='......Library Management Application...... ',font=('arial',24))
l.pack()
Left=Frame(root,width=500,height=100,bd=8,relief='raise')
Left.pack(side=LEFT)
Right=Frame(root,width=500,height=500,bd=8,relief='raise')
Right.pack(side=RIGHT)
Forms=Frame(Left,width=500,height=500)
Forms.pack(side=TOP)
Buttons=Frame(Left,width=300,height=50,bd=8,relief='raise')
Buttons.pack(side=BOTTOM)

l1=Label(Forms,text='Booktitle:',font=('arial',16),bd=15)
l1.grid(row=0,column=0)
l2=Label(Forms,text='Author:',font=('arial',16),bd=15)
l2.grid(row=1,column=0)
l3=Label(Forms,text='Year:',font=('arial',16),bd=15)
l3.grid(row=2,column=0)
l4=Label(Forms,text='ISBN:',font=('arial',16),bd=15)
l4.grid(row=3,column=0)
text_result=Label(Buttons)
text_result.pack(side=TOP)

# Variable decalration

Booktitle=StringVar()
Author=StringVar()
Year=IntVar()
ISBN=IntVar()

e1=Entry(Forms,textvariable=Booktitle,width=30)
e1.grid(row=0,column=1)
e2=Entry(Forms,textvariable=Author,width=30)
e2.grid(row=1,column=1)
e3=Entry(Forms,textvariable=Year,width=30)
e3.grid(row=2,column=1)

e4=Entry(Forms,textvariable=ISBN,width=30)
e4.grid(row=3,column=1)



b1=Button(Buttons,width=10,text='Display',command=Display)
b1.pack(side=LEFT)
b2=Button(Buttons,width=10,text='Search',command=search)
b2.pack(side=LEFT)
b3=Button(Buttons,width=10,text='Add',command=Add)
b3.pack(side=LEFT)
b4=Button(Buttons,width=10,text='Issue',command=issue)
b4.pack(side=LEFT)
b5=Button(Buttons,width=10,text='Delete',command=delete)
b5.pack(side=LEFT)
b6=Button(Buttons,width=10,text='Exit',command=exit)
b6.pack(side=LEFT)

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)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM,fill=X)

tree.heading('Booktitle',text='Booktitle',anchor=W)
tree.column('#0',stretch=NO,minwidth=0,width=0)
tree.heading('Author',text='Author',anchor=W)
tree.column('#1',stretch=NO,minwidth=0,width=200)
tree.heading('Year',text='Year',anchor=W)
tree.column('#2',stretch=NO,minwidth=0,width=150)
tree.heading('ISBN',text='ISBN',anchor=W)
tree.column('#3',stretch=NO,minwidth=0,width=80)
tree.pack()


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.

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.