Challenge

Project 1 - English Dictionary App & Library Book Management System

Project 1 - English Dictionary App & Library Book Management System

1A: English Dictionary App

In [1]:
import json
​
print ('Welcome to Dictionary App')
print('Main Manu')
print('Please select your choice')
print('1. Add a new word')
print('2. Find the meaning of a word')
print('3. Update a word ')
print('4. Exit')
​
f = open('words.txt','w')
my_dic = {}
json.dump(my_dic,f)
f.close()
​
while True:
    n = int(input('Enter the Choice:'))
    if n == 1:
        f = open('words.txt','w')
        word = input('Enter a word : ')
        meaning = input('Enter its meaning : ')
        my_dic[word] = meaning
        json.dump(my_dic,f)
        f.close()
     
    elif n == 2:
        f = open('words.txt','r+')
        dic = json.load(f)
        find = input('Enter the word to find: ')
        if find in my_dic:
            print('The meaning is',my_dic.get(find))
        else:
            print('Sorry the word is not found')
        json.dump(my_dic,f)
        f.close()
           
    elif n==3:
        f = open('words.txt','w')  
        word1 = input('Enter the word :')
        update_meaning = input('Enter new meaning of word :')
        my_dic[word1] =  update_meaning
        json.dump = (my_dic,f)
        f.close()
       
    elif n== 4:
        print('Thank you for choosing dictionary app.')
        break
       
    else:
        print('Main Manu')
        print('Please entered mentioned choice')
        print('1. Add a new word')
        print('2. Find the meaning of a word')
        print('3. Update a word ')
        print('4. Exit')
Welcome to Dictionary App
Main Manu
Please select your choice
1. Add a new word
2. Find the meaning of a word
3. Update a word 
4. Exit
Enter the Choice:1
Enter a word : apple
Enter its meaning : fruit
Enter the Choice:2
Enter the word to find: apple
The meaning is fruit
Enter the Choice:3
Enter the word :apple
Enter new meaning of word :red fruit
Enter the Choice:4
Thank you for choosing dictionary app.

1B: Library Book Management System

In [7]:
from tkinter import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox
In [8]:
root = Tk()
root.title('Library Management Application')
Out[8]:
''
In [9]:
def Database():
    global conn,cursor
    conn = sqlite3.connect('Books.db')
    cursor = conn.cursor()
    cursor.execute('CREATE TABLE IF NOT EXISTS record (rec_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,booktitle TEXT,author TEXT,year INTEGER,isbn INTEGER)')
    
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 record(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 record")
    fetch = cursor.fetchall()
    for data in fetch:
        tree.insert('','end',values=(data[1],data[2],data[3],data[4]))
    cursor.close()
    txt_result.config(text="Successfuly fetched data !",fg="black")
    
def Exit():
    result = tkMessageBox.askquestion('Do you want to exit ? (y/n)',icon='warning')
    if result == 'yes':
        root.destroy()
        exit()
In [10]:
BOOKTITLE = StringVar()
AUTHOR = StringVar()
YEAR = StringVar()
ISBN = StringVar()
​
In [11]:
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)
In [*]:
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)
​
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)
​
​
btn_create = Button(Buttons, width=10, text="Display", command=Create)
btn_create.pack(side=LEFT)
btn_read = Button(Buttons, width=10, text="Search", command=Read)
btn_read.pack(side=LEFT)
btn_update = Button(Buttons, width=10, text="Add", command=DISABLED)
btn_update.pack(side=LEFT)
btn_issue = Button(Buttons, width=10, text="Issue", command=DISABLED)
btn_issue.pack(side=LEFT)
btn_delete = Button(Buttons, width=10, text="Delete", command=DISABLED)
btn_delete.pack(side=LEFT)
btn_exit = Button(Buttons, width=10, text="Exit", command=Exit)
btn_exit.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.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.pack()
​
if __name__ == '__main__':
    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.