Python Contact - Book
Python Contact - Book
pySkip to content
Python Contact Book – Address Book Project
FREE Online Courses: Dive into Knowledge for Free. Learn More!
Contact book is a GUI-based project built using Python Tkinter module 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.
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.
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.
from tkinter import messagebox – Import message box separately for showing messages on the
screen.
Name = StringVar()
Number = StringVar()
Code Explanation-
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])
Code Explanation-
def UpdateDetail():
if Name.get() and Number.get():
contactlist[Selected()] = [Name.get(), Number.get()]
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-
def VIEW():
NAME, PHONE = contactlist[Selected()]
Name.set(NAME)
Number.set(PHONE)
Code Explanation-
def Select_set() :
contactlist.sort()
select.delete(0,END)
for name,phone in contactlist :
select.insert (END, name)
Select_set()
Code Explanation-
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, RESET, EXIT and setting their font,
background color, and setting proper position using the .place method.
Python Contact Book Project Output
python contact book output
Summary
We have successfully created a python contact book project using the Graphical user
Interface(GUI). We have learned about the Tkinter module.