Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Python Micro

The document outlines a microproject on creating a 'Contact Book' using Python, specifically utilizing the Tkinter module for a GUI interface. It includes details about the project, the students involved, and the steps necessary to build the application, which allows users to add, edit, delete, and view contacts. Additionally, it provides a program code and explanations for various functions implemented in the project.

Uploaded by

rohitjadhav02085
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Micro

The document outlines a microproject on creating a 'Contact Book' using Python, specifically utilizing the Tkinter module for a GUI interface. It includes details about the project, the students involved, and the steps necessary to build the application, which allows users to add, edit, delete, and view contacts. Additionally, it provides a program code and explanations for various functions implemented in the project.

Uploaded by

rohitjadhav02085
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

lOMoAR cPSD| 37250859

GOVERNMENT POLYTECHNIC, JINTUR


COMPUTER ENGINEERING Department

Academic year: 2024-25


Microproject on

“CONTACT BOOK IN PYTHON ”

Program Name: COMPUTER ENGINEERING

Program Code: CO6I

Course Name: PYTHON

Course Code: 22616

SR.NO NAME OF STUDENTS Roll NO ENROLLNMENNT NO


1) NILWARN SUMIT DHANANJAY CO334 2200940109

2) JADHAV ROHIT RAMESH CO338 2200940120

3) DAHIWAL OMKAR SURESH CO341 2200940126

1
lOMoAR cPSD| 37250859

MAHARASHTRA STATE
BOARD OF TECHNICAL
EDUCATION

Certificate

This is to certify that Mr. NILWARN SUMIT D, JADHAV ROHIT ,R,DAHIWAL OMKAR S,
Roll No.C0334,CO338,CO341 of 5th Semester of Diploma in COMPUTER

ENGINEERING of Institute, GOVERNMENT POLYTECHNIC, JINTUR (0094) has

completed the Mi- cro Project satisfactorily in Subject- Entrepreneurship


Development for the academic year 2024-25 as prescribed in the curriculum.

Place: JIINTUR

Date:

Subject Teacher Head of the Department Principal


PROF.P.B.KALE.SIR PROF.P.B.KALE.SIR DR.S.WESSLEY.SIR

2
lOMoAR cPSD| 37250859

ABSTRACT

Contact book is a GUI-based project built using Python Thinter mod-


ule and message module. A contact book is used to store some person’s
contacts like name, phone number etc. In this project, we’ll build our
own contact book using the python programming language.

What is the Contact Book?

Contact book is a widely used kind of application. Probably we have


seen earlier that our parents used to store information about our family
members, friends, coworkers, and so on in a diary in the form of names
and contact numbers.
Here we are building the same in python.

3
lOMoAR cPSD| 37250859

INDEX

Sr.No Content Pg.No

1) 3
Introduction

2) 5
CONTACT BOOK DETAILS

3) STEPS TO BUILT CONTACT BOOK 7

4) PROGRAM OF CONATCT 17

BOOK

5) 24
OUPTUTS

6) 25
CONCLUSION

7) 25
REFERENCE

4
lOMoAR cPSD| 37250859

Introduction

Contact book is a GUI-based project built using Python Thinter module


and message module. A contact book is used to store some person’s con-
tacts like name, phone number etc. In this project, we’ll build our own
contact book using the python programming language.

What is the Contact Book?


Contact book is a widely used kind of application. Probably we have
seen earlier that our parents used to store information about our family
members, friends, coworkers, and so on in a diary in the form of names
and contact numbers.
Here we are building the same in python.

Python Contact Book Project Details


Contact Book is a GUI based project using Thinter and a message mod-
ule used for storing information about some person like name and con-
tact number. In this project we have some functionality like add, edit,
delete, view, and reset contacts.

5
lOMoAR cPSD| 37250859

We can add new contacts by clicking on the add button and filling in the
information of the new contact. We can update or edit existing contacts
by selecting and clicking on the edit button. Similarly, we can delete and
view the contact. Like this, we can store data.

Python Contact Book Project Prerequisite


This project requires good knowledge of python and the Thinter library.
Thinter is the python binding to the Tk toolkit which is used across
many programming languages for building the Graphical user interface
which is a GUI. Also familiar with the Thinter message box which is
used to display the message box on the python game window.

6
lOMoAR cPSD| 37250859

 Steps to Build a Contact Book in Python:

1. Import Modules
2. Initializing the window
3. Create frame
4. Function to get select value
5. Function to add new contact and edit existing contact
6. Function to delete and view contact
7. Exit the game window
8. Define buttons labels and entry widget

Step 1- Importing Modules


#PythonGeeks - import library
from tkinter import *
from tkinter import messagebox
Code Explanation
 Tkinter module – Tkinter is the standard interface in python
for creating a GUI that is Graphical User Interface.
 tkinter import * – import everything from the module.

7
lOMoAR cPSD| 37250859

 from thinter import message box :-


 Import message box separately for showing messages on the
screen.

Step 2- Initializing the window


#PythonGeeks address book - Initialize window
root = Tk()
root.geometry('700x550') root.config(bg
= '#d3f3f5') root.title('PythonGeeks
Contact Book') root.resizable(0,0)
contactlist = [
['Siddharth Nigam','369854712'],
['Gaurav Patil', '521155222'],
['Abhishek Nikam', '78945614'],
['Sakshi Gaikwad', '58745246'],
['Mohit Paul', '5846975'],
['Karan Patel', '5647892'],
['Sam Sharma', '89685320'],
['John Maheshwari', '98564785'],

8
lOMoAR cPSD| 37250859

['Ganesh Pawar','85967412']
]
Name = StringVar()
Number = StringVar()
Code Explanation-
 root – Initializing the root window of Python contact book Project.
 .title – Use to set title to window.
 .geometry – For setting dimensions of a window in pixels.
 .config – Used to configure attributes to the window, such as
back- ground color.
 contactlist – For storing a database of the project in the list in
name and phone number format.
Step 3- Create frame
#PythonGeeks - create frame
frame = Frame(root)
frame.pack(side = RIGHT)
scroll = Scrollbar(frame, orient=VERTICAL)
select = Listbox(frame, yscrollcommand=scroll.set, font=('Times new
roman' ,16), bg="#f0fffc", width=20, height=20, borderwidth=3, relief=
"groove")
scroll.config (command=select.yview)

9
lOMoAR cPSD| 37250859

scroll.pack(side=RIGHT, fill=Y)
select.pack(side=LEFT, fill=BOTH, expand=1)
Code Explanation-
 Frame – For creating a frame.
 .pack() – This puts the widget inside the frame. And declare the
po- sition of the widget in relation with each other.
 listbox – listbox is the tkinter toolkit used for displaying more than
one item.
 scroll – Here we are creating a frame at the right side of the win-
dow which will show our listbox. And the scrollbar controls the
up and down moment of the listbox.
 We are making a listbox and setting their font background
color, width, height, border width, and set command as scroll.
Step 4- Function to get select value
#PythonGeeks - function to get select value
def Selected():
print("hello",len(select.curselection()))
if len(select.curselection())==0:
messagebox.showerror("Error", "Please Select the Name")
else:
return int(select.curselection()[0])

10
lOMoAR cPSD| 37250859

Code Explanation-
 Selected() – Function for selecting the values.
 curselection() – curselection is the tkinter toolkit used for
display- ing the selected items.
 len – Used to count the length of data.
 If the length of curselection is equal to 0 means we don’t select
an- ything, then a message will pop up on the screen that says
“Error”, “Please Select the Name”.
Step 5- Function to add new contact and edit existing contact
#PythonGeeks -fun to add new contact
def AddContact():
if Name.get()!="" and Number.get()!="":
contactlist.append([Name.get() ,Number.get()])
print(contactlist)
Select_set()
EntryReset()
messagebox.showinfo("Confirmation", "Successfully Add New Con-
tact")
else:
messagebox.showerror("Error","Please fill the information")
def UpdateDetail():

11
lOMoAR cPSD| 37250859

if Name.get() and Number.get():


contactlist[Selected()] = [Name.get(), Number.get()]
messagebox.showinfo("Confirmation", "Successfully Update Contact")
EntryReset()
Select_set()
elif not(Name.get()) and not(Number.get()) and not(len(select.curselec-
tion())==0):
messagebox.showerror("Error", "Please fill the information")
else:
if len(select.curselection())==0:
messagebox.showerror("Error", "Please Select the Name and \n press
Load button")
else:
message1 = """To Load the all information of \n
selected row press Load button\n.
"""
messagebox.showerror("Error", message1)
Code Explanation-
 AddContact() – Function for adding new contact.
 .get() – It returns the value of the name and number with the
spe- cific key.

12
lOMoAR cPSD| 37250859

 .append – This is used to add new data in the existing list. It


ap- pends the contact list and adds new contacts in it.
 After successfully adding new contact in the list message will
pop up “Confirmation, Successfully Add New Contact”.
 Else “Error, Please fill the information” message will pop up.
 UpdateDetail() – Function for editing existing contact.
 Here first we have to select the contact then click on view
button then edit the contact and then click on edit button
 After successfully editing contact in the list message will pop
up “Confirmation, Successfully Update Contact”.
 Else “Error, Please fill the information” message will pop up.
 If the length of curselection is equal to 0 then a message will pop
up on the screen that says “Error”, “Please Select the Name”.
Step 6- Function to delete and view contact
def Delete_Entry():
if len(select.curselection())!=0:
result=messagebox.askyesno('Confirmation','You Want to Delete Con-
tact\n Which you selected')
if result==True:
del contactlist[Selected()]
Select_set()
else:

13
lOMoAR cPSD| 37250859

messagebox.showerror("Error", 'Please select the Contact')


def VIEW():
NAME, PHONE = contactlist[Selected()]
Name.set(NAME)
Number.set(PHONE)
Code Explanation-
 Delete_Entry() – Function for deleting selected contact.
 If the length of curselection is not equal to 0 then a message will
pop up on the screen that asks for confirmation that you want to
de- lete selected contact? Yes or no.
 First we have to select a particular contact otherwise an error mes-
sage will pop up “Error”, ‘Please select the Contact’.
 VIEW() – Function to view selected contact.
 First select a particular contact and then click on the view button.
Step 7- Exit the game window
# exit game window
def EXIT():
root.destroy()
def Select_set() :
contactlist.sort()
select.delete(0,END)

14
lOMoAR cPSD| 37250859

for name,phone in contactlist :


select.insert (END, name)
Select_set()
Code Explanation-
 EXIT() – Function to exit game window.
 .destroy() – This is used when the process is completed by the
user, then for destroying GUI components as well as clearing the
screen.
 .sort() – This method sorts the contact list in ascending order
by default.
Step 8- Define buttons labels and entry widget
#PythonGeeks - define buttons labels and entry widget
Label(root, text = 'Name', font=("Times new roman",22,"bold"), bg =
'SlateGray3').place(x= 30, y=20)
Entry(root, textvariable = Name, width=30).place(x= 200, y=30)
Label(root, text = 'Contact No.', font=("Times new roman",20,"bold"),bg
= 'SlateGray3').place(x= 30, y=70)
Entry(root, textvariable = Number, width=30).place(x= 200, y=80)
Button(root,text=" ADD", font='Helvetica 18 bold',bg='#e8c1c7', com-
mand = AddContact, padx=20). place(x= 50, y=140)
Button(root,text="EDIT", font='Helvetica 18 bold',bg='#e8c1c7',com-
mand = UpdateDetail, padx=20).place(x= 50, y=200)

15
lOMoAR cPSD| 37250859

Button(root,text="DELETE", font='Helvetica 18
bold',bg='#e8c1c7',command = Delete_Entry, padx=20).place(x= 50,
y=260)
Button(root,text="VIEW", font='Helvetica 18 bold',bg='#e8c1c7', com-
mand = VIEW).place(x= 50, y=325)
Button(root,text="RESET", font='Helvetica 18 bold',bg='#e8c1c7', com-
mand = EntryReset).place(x= 50, y=390)
Button(root,text="EXIT", font='Helvetica 24 bold',bg='tomato', com-
mand = EXIT).place(x= 250, y=470)
root.mainloop()
Code Explanation-
 label – In this variable we use the label widget for displaying the
box in which we give text. Then call configure to set font, font
size, and background color.
 Here we are creating buttons ADD, EDIT, DELETE, VIEW,
RE- SET, EXIT and setting their font, background color, and
setting proper position using the .place method.

16
lOMoAR cPSD| 37250859

PROGRAM:
#PythonGeeks - import library from
tkinter import *
from tkinter import messagebox

#PythonGeeks - Initialize window


root = Tk()
root.geometry('700x550')
root.config(bg = '#d3f3f5')
root.title('PythonGeeks Contact Book')
root.resizable(0,0)
contactlist = [
[' Sumit Nilwarn','369854712'], ['
Omkar Dahiwal', '521155222'],
[' Rohit Jadhav','369854712'],
['Abhishek Nikam', '78945614'],
['Sakshi Gaikwad', '58745246'],
['Mohit Paul', '5846975'],

17
lOMoAR cPSD| 37250859

['Karan Patel', '5647892'],


['Sam Sharma', '89685320'],
['John Maheshwari', '98564785'],
['Ganesh Pawar','85967412']
]

Name = StringVar()
Number = StringVar()

#PythonGeeks - create frame


frame = Frame(root)
frame.pack(side = RIGHT)

scroll = Scrollbar(frame, orient=VERTICAL)


select = Listbox(frame, yscrollcommand=scroll.set,font=('Times
new roman',16),bg="#f0fffc",width=20,height=20,borderwidth=3,re-
lief="groove")
scroll.config (command=select.yview)
scroll.pack(side=RIGHT, fill=Y)
select.pack(side=LEFT, fill=BOTH, expand=1)

18
lOMoAR cPSD| 37250859

#PythonGeeks - function to get select value

def Selected():
print("hello",len(select.curselection()))
if len(select.curselection())==0:
messagebox.showerror("Error", "Please Select the Name")
else:
return int(select.curselection()[0])

#PythonGeeks -function to add new contact


def AddContact():
if Name.get()!="" and Number.get()!="":
contactlist.append([Name.get() ,Number.get()])
print(contactlist)
Select_set()
EntryReset()
messagebox.showinfo("Confirmation", "Successfully Add New
Contact")

else:
messagebox.showerror("Error","Please fill the information")

19
lOMoAR cPSD| 37250859

# fun to edit existing contact

def UpdateDetail():
if Name.get() and Number.get():
contactlist[Selected()] = [Name.get(),
Number.get()]

messagebox.showinfo("Confirmation", "Successfully Update Con-


tact")
EntryReset()
Select_set()

elif not(Name.get()) and not(Number.get()) and not(len(select.curse-


lection())==0):
messagebox.showerror("Error", "Please fill the information")

else:
if len(select.curselection())==0:
messagebox.showerror("Error", "Please Select the Name and \n
press Load button")

20
lOMoAR cPSD| 37250859

else:
message1 = """To Load the all information of \n
selected row press Load button\n.
"""
messagebox.showerror("Error", message1)

def EntryReset():
Name.set('')
Number.set('')

#PythonGeeks- function to delete selected contact


def Delete_Entry():
if len(select.curselection())!=0:
result=messagebox.askyesno('Confirmation','You Want to Delete
Contact\n Which you selected')
if result==True:
del contactlist[Selected()]
Select_set()
else:
messagebox.showerror("Error", 'Please select the Contact')

21
lOMoAR cPSD| 37250859

# func to view contact


def VIEW():
NAME, PHONE = contactlist[Selected()]
Name.set(NAME)
Number.set(PHONE)

#PythonGeeks- function to exit game window


def EXIT():
root.destroy()

def Select_set() :
contactlist.sort()
select.delete(0,END)
for name,phone in contactlist :
select.insert (END, name)
Select_set()

#PythonGeeks - define buttons labels and entry widget

22
lOMoAR cPSD| 37250859

Label(root, text = 'Name', font=("Times new roman",25,"bold"), bg =


'SlateGray3').place(x= 30, y=20)
Entry(root, textvariable = Name, width=30).place(x= 200, y=30)
Label(root, text = 'Contact No.', font=("Times new roman",22,"bold"),bg
= 'SlateGray3').place(x= 30, y=70)
Entry(root, textvariable = Number, width=30).place(x= 200, y=80)

Button(root,text=" ADD", font='Helvetica 18 bold',bg='#e8c1c7', com-


mand = AddContact, padx=20). place(x= 50, y=140)
Button(root,text="EDIT", font='Helvetica 18 bold',bg='#e8c1c7',com-
mand = UpdateDetail, padx=20).place(x= 50, y=200)
Button(root,text="DELETE", font='Helvetica 18
bold',bg='#e8c1c7',command = Delete_Entry, padx=20).place(x= 50,
y=260)
Button(root,text="VIEW", font='Helvetica 18 bold',bg='#e8c1c7', com-
mand = VIEW).place(x= 50, y=325)
Button(root,text="RESET", font='Helvetica 18 bold',bg='#e8c1c7', com-
mand = EntryReset).place(x= 50, y=390)
Button(root,text="EXIT", font='Helvetica 24 bold',bg='tomato', command =
EXIT).place(x= 250, y=470)

root.mainloop()

23
lOMoAR cPSD| 37250859

OUTPUT:

24
lOMoAR cPSD| 37250859

CONCLUSION:
We have successfully created a python contact book pro-
ject using the Graphical user Interface(GUI). We have
learned about the Thinter module.

Reference:
1) www.google.com
2) www.chatgpt.com

25

You might also like