In this Python Tutorial, we will learn about How we can create Address Book using Python Tkinter and we will add all the GUI components.
Python Tkinter Address Book
In this section, we will learn about how to create an Address Book in Python Tkinter. A Address Book is a book that is used for recording the names, addresses, and phone numbers of friends, relatives, etc.

Block of Code:
In this block of code, we are creating a user-defined function to reprocess the operations.
The function which is used for creating the program are:
- addinfo: add is used to add a record in the address book.
- viewinfo: view info represents all the values of the selected record.
- deleteinfo: delete is used to delete the selected record from the address book.
- resetinfo: reset is used to reset all the values of the input parameters.
- updateinfo: update is used to update the information of the whole address book.
# Import Module
from tkinter import *
import tkinter
# Create Object
ws = Tk()
# Set geometry
ws.geometry('600x500')
# Information List
datalist = []
# Add Information
def addinfo():
global datalist
datalist.append([PersonName.get(),phoneNumber.get(),personaladdress.get(1.0, "end-1c")])
updatebookinfo()
# View Information
def viewinfo():
PersonName.set(datalist[int(select.curselection()[0])][0])
phoneNumber.set(datalist[int(select.curselection()[0])][1])
personaladdress.delete(1.0,"end")
personaladdress.insert(1.0, datalist[int(select.curselection()[0])][2])
# Delete Information
def deleteinfo():
del datalist[int(select.curselection()[0])]
updatebookinfo()
def resetinfo():
PersonName.set('')
phoneNumber.set('')
personaladdress.delete(1.0,"end")
# Update Information
def updatebookinfo():
select.delete(0,END)
for n,p,a in datalist:
select.insert(END, n)
Github Link
Check this code in the Repository from Github and you can also fork this code.
Github User Name: PythonT-Point
Block of Code:
In this block of code, we will add all the GUI components like labels, text, and buttons for creating a program.
- frame: frame is used to create a rectangular region on the screen.
- Label: label widget is used to implement display boxes where we can place text or images.
- Entry: The entry widget is used to enter or display a single line.
- Button: The button widget is used to add the button. The button can display text or images when we hit on them.
- Scrollbar: Scroll bar is used to scroll up or down the content
# Add Buttons, Label, ListBox
PersonName = StringVar()
phoneNumber = StringVar()
frame = Frame()
frame.pack(pady=10)
frame1 = Frame()
frame1.pack()
frame2 = Frame()
frame2.pack(pady=10)
Label(frame, text = 'PersonName', font='arial 14 bold').pack(side=LEFT)
Entry(frame, textvariable = PersonName,width=50).pack()
Label(frame1, text = 'Phone No.', font='arial 14 bold').pack(side=LEFT)
Entry(frame1, textvariable = phoneNumber,width=50).pack()
Label(frame2, text = 'Address', font='arial 14 bold').pack(side=LEFT)
personaladdress = Text(frame2,width=37,height=10)
personaladdress.pack()
Button(ws,text="Add",font="arial 14 bold",command=addinfo).place(x= 102, y=272)
Button(ws,text="View",font="arial 14 bold",command=viewinfo).place(x= 102, y=312)
Button(ws,text="Delete",font="arial 14 bold",command=deleteinfo).place(x= 102, y=352)
Button(ws,text="Reset",font="arial 14 bold",command=resetinfo).place(x= 102, y=392)
scrollbar = Scrollbar(ws, orient=VERTICAL)
select = Listbox(ws, yscrollcommand=scrollbar.set, height=14)
scrollbar.config (command=select.yview)
scrollbar.pack(side=RIGHT, fill=Y)
select.place(x=200,y=260)
# Execute Tkinter
ws.mainloop()
Code:
After dividing the code and explaining how we can create an Address Box using Python Tkinter. Now we will see what the output looks like after running the whole code.
# Import Module
from tkinter import *
import tkinter
# Create Object
ws = Tk()
# Set geometry
ws.geometry('600x500')
# Information List
datalist = []
# Add Information
def addinfo():
global datalist
datalist.append([PersonName.get(),phoneNumber.get(),personaladdress.get(1.0, "end-1c")])
updatebookinfo()
# View Information
def viewinfo():
PersonName.set(datalist[int(select.curselection()[0])][0])
phoneNumber.set(datalist[int(select.curselection()[0])][1])
personaladdress.delete(1.0,"end")
personaladdress.insert(1.0, datalist[int(select.curselection()[0])][2])
# Delete Information
def deleteinfo():
del datalist[int(select.curselection()[0])]
updatebookinfo()
def resetinfo():
PersonName.set('')
phoneNumber.set('')
personaladdress.delete(1.0,"end")
# Update Information
def updatebookinfo():
select.delete(0,END)
for n,p,a in datalist:
select.insert(END, n)
# Add Buttons, Label, ListBox
PersonName = StringVar()
phoneNumber = StringVar()
frame = Frame()
frame.pack(pady=10)
frame1 = Frame()
frame1.pack()
frame2 = Frame()
frame2.pack(pady=10)
Label(frame, text = 'PersonName', font='arial 14 bold').pack(side=LEFT)
Entry(frame, textvariable = PersonName,width=50).pack()
Label(frame1, text = 'Phone No.', font='arial 14 bold').pack(side=LEFT)
Entry(frame1, textvariable = phoneNumber,width=50).pack()
Label(frame2, text = 'Address', font='arial 14 bold').pack(side=LEFT)
personaladdress = Text(frame2,width=37,height=10)
personaladdress.pack()
Button(ws,text="Add",font="arial 14 bold",command=addinfo).place(x= 102, y=272)
Button(ws,text="View",font="arial 14 bold",command=viewinfo).place(x= 102, y=312)
Button(ws,text="Delete",font="arial 14 bold",command=deleteinfo).place(x= 102, y=352)
Button(ws,text="Reset",font="arial 14 bold",command=resetinfo).place(x= 102, y=392)
scrollbar = Scrollbar(ws, orient=VERTICAL)
select = Listbox(ws, yscrollcommand=scrollbar.set, height=14)
scrollbar.config (command=select.yview)
scrollbar.pack(side=RIGHT, fill=Y)
select.place(x=200,y=260)
# Execute Tkinter
ws.mainloop()
Output:
After running the above code, we get the following output in which we can see that an Address book is created using python Tkinter.

So, in this tutorial, we have illustrated how to create an Address Book in Python Tkinter. Moreover, we have also discussed the whole code used in this tutorial.
Also, take a look at some more tutorials related to Python Tkinter.
Python Tkinter temperature converter
Python Tkinter Simple Calculator
Stone Paper Scissor using Python Tkinter
Python Tkinter Instagram User Detail

Comments are closed.