Contact Management System Project in Python With Source Code
The Contact Management System Project in Python With Source Code undertaking is written in Python. A Contact Management System project report incorporates a python script (Contact-System.Py). This is a simple GUI based mission that’s very clean to apprehend and use. Talking about the device, it includes all the required features which encompass including, viewing, deleting and updating contact lists.
Before we proceed, watch the video here of the running Contact Management System Project in Python With Source code.
While including the contact of a person, he/she has to provide first name, closing name, gender, deal with and call info. The user can additionally update the touch list if he/she wishes to. For this, the person has to double-click on on a file that he/she wishes to edit.
The Contact Management System shows the touch details in a listing view. And additionally the user easily delete any touch info. There’s an external database connection file used in this mini project to save user’s data permanently.
Before you start to create a Contact Management System Project in Python With Source Code, make sure you have PyCharm IDE and Sqlite3 installed in your computer.
This are the steps how to create Contact Management System Project in Python.
Contact Management System Project in Python With Source Code
- Step 1: Create a Project Name
First step open the PyCharm IDE and click “File” and select “New Project” and then create a project name after that click the “create” button.
- Step 2: Create a Python File
Second step after creating a project name, “right” click the project name and the click “New” after that choose “Python File“.
- Step 3: Name the Python File
Third step after choose Python File name the file “Contact-System” and then click “Enter“.
- Step 4: The actual code
Now you can start coding, you are free to copy the code that being provided below.
The code given below, which is for declaring the variables
1 |
f_name = StringVar()<br>m_name = StringVar()<br>l_name = StringVar()<br>age = StringVar()<br>home_address = StringVar()<br>phone_number = StringVar()<br>gender = StringVar()<br>religion = StringVar()<br>nationality = StringVar() |
This module is for the exit function of a system
1 2 3 4 5 |
def Exit(): wayOut = tkinter.messagebox.askyesno("Contact Management System", "Do you want to exit the system") if wayOut > 0: root.destroy() return |
In the code above, This method is used to ask the user about some action to which, the user can answer in yes or no. If yes it will close the GUI and if no it will return back the main display. (Contact Management System Project in Python With Source Code)
When the above code is executed, it produces the following result below.
Output:

This module is for the reset function
1 |
def Reset():<br> f_name.set("")<br> m_name.set("")<br> l_name.set("")<br> gender.set("")<br> age.set("")<br> home_address.set("")<br> phone_number.set("")<br> religion.set("")<br> nationality.set("") |
In the code above, Which is for clearing the value you put in the text entry of adding new contacts.
This module is for the database
1 2 3 4 5 6 7 8 9 10 11 |
def Database(): conn = sqlite3.connect("contactdb.db") cursor = conn.cursor() cursor.execute( "CREATE TABLE IF NOT EXISTS `contactable` (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, first_name TEXT, middle_name TEXT, last_name TEXT, gender TEXT, age TEXT, home_address TEXT, phone_number TEXT, religion TEXT, nationality TEXT)") cursor.execute("SELECT * FROM `contactable` ORDER BY `last_name` ASC") fetch = cursor.fetchall() for data in fetch: tree.insert('', 'end', values=(data)) cursor.close() conn.close() |
In the code above, This method used for how to create a database name and table name.
This module is for Insert Query in a database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
def Submit(): if f_name.get() == "" or m_name.get() == "" or l_name.get() == "" or gender.get() == "" or age.get() == "" or home_address.get() == "" or phone_number.get() == "" or religion.get() == "" or nationality.get() == "": result = tkMessageBox.showwarning('', 'Please Complete The Required Field', icon="warning") else: tree.delete(*tree.get_children()) conn = sqlite3.connect("contactdb.db") cursor = conn.cursor() cursor.execute( "INSERT INTO `contactable` (first_name, middle_name, last_name, gender, age, home_address, phone_number, religion, nationality) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", (str(f_name.get()), str(m_name.get()), str(l_name.get()), str(gender.get()), int(age.get()), str(home_address.get()), int(phone_number.get()), str(religion.get()), str(nationality.get()))) conn.commit() cursor.execute("SELECT * FROM `contactable` ORDER BY `last_name` ASC") fetch = cursor.fetchall() for data in fetch: tree.insert('', 'end', values=(data)) cursor.close() conn.close() f_name.set("") m_name.set("") l_name.set("") gender.set("") age.set("") home_address.set("") phone_number.set("") religion.set("") nationality.set("") |
The code above, This method demonstrates how to execute INSERT Query from python to add a new row into MySQLite table.(Contact Management System Project in Python With Source Code)
This module is for Update Query in a database
1 |
def Update():<br> if gender.get() == "":<br> result = tkMessageBox.showwarning('', 'Please Complete The Required Field', icon="warning")<br> else:<br> tree.delete(*tree.get_children())<br> conn = sqlite3.connect("contactdb.db")<br> cursor = conn.cursor()<br> cursor.execute(<br> "UPDATE `contactable` SET `first_name` = ?, `middle_name` = ? , `last_name` = ?, `gender` =?, `age` = ?, `home_address` = ?, `phone_number` = ?, `religion` = ?, `nationality` = ? WHERE `id` = ?",<br> (str(f_name.get()), str(m_name.get()), str(l_name.get()), str(gender.get()), int(age.get()), str(home_address.get()),<br> str(phone_number.get()), str(religion.get()), str(nationality.get()), int(id)))<br> conn.commit()<br> cursor.execute("SELECT * FROM `contactable` ORDER BY `last_name` ASC")<br> fetch = cursor.fetchall()<br> for data in fetch:<br> tree.insert('', 'end', values=(data))<br> cursor.close()<br> conn.close()<br> f_name.set("")<br> m_name.set("")<br> l_name.set("")<br> gender.set("")<br> age.set("")<br> home_address.set("")<br> phone_number.set("")<br> religion.set("")<br> nationality.set("") |
The code above, This method used how to UPDATE Query from python to edit a new row into MySQLite table.
This module is for the update contact form window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
def UpdateContactWindow(event): global id, UpdateWindow curItem = tree.focus() contents = (tree.item(curItem)) selecteditem = contents['values'] id = selecteditem[0] f_name.set("") m_name.set("") l_name.set("") gender.set("") age.set("") home_address.set("") phone_number.set("") religion.set("") nationality.set("") f_name.set(selecteditem[1]) m_name.set(selecteditem[2]) l_name.set(selecteditem[3]) age.set(selecteditem[5]) home_address.set(selecteditem[6]) phone_number.set(selecteditem[7]) religion.set(selecteditem[8]) nationality.set(selecteditem[9]) UpdateWindow = Toplevel() UpdateWindow.title("Contact Details") UpdateWindow.geometry("500x520+0+0") UpdateWindow.config(bg="dark gray") UpdateWindow.resizable(0, 0) if 'NewWindow' in globals(): NewWindow.destroy() |
In the code above, This method used how to update a contact record in a table.(Contact Management System Project in Python With Source Code)
This module is for the frame, labels, text entry, and button for update contact form window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# FRAMES FormTitle = Frame(UpdateWindow) FormTitle.pack(side=TOP) ContactForm = Frame(UpdateWindow) ContactForm.pack(side=TOP, pady=10) RadioGroup = Frame(ContactForm) Male = Radiobutton(RadioGroup, text="Male", variable=gender, value="Male", font=('arial', 14)).pack(side=LEFT) Female = Radiobutton(RadioGroup, text="Female", variable=gender, value="Female", font=('arial', 14)).pack(side=LEFT) Transgender = Radiobutton(RadioGroup, text="Transgender", variable=gender, value="Transgender", font=('arial', 14)).pack(side=LEFT) # LABELS lbl_title = Label(FormTitle, text="Updating Contacts", bd=12, relief=GROOVE, fg="White", bg="blue", font=("Calibri", 14, "bold"), pady=3) lbl_title.pack(fill=X) lbl_FirstName = Label(ContactForm, text="First Name", font=('arial', 14), bd=5) lbl_FirstName.grid(row=0, sticky=W) lbl_MiddleName = Label(ContactForm, text="Middle Name", font=('arial', 14), bd=5) lbl_MiddleName.grid(row=1, sticky=W) lbl_LastName = Label(ContactForm, text="Last Name", font=('arial', 14), bd=5) lbl_LastName.grid(row=2, sticky=W) lbl_Gender = Label(ContactForm, text="Gender", font=('arial', 14), bd=5) lbl_Gender.grid(row=3, sticky=W) lbl_Age = Label(ContactForm, text="Age", font=('arial', 14), bd=5) lbl_Age.grid(row=4, sticky=W) lbl_HomeAddress = Label(ContactForm, text=" Home Address", font=('arial', 14), bd=5) lbl_HomeAddress.grid(row=5, sticky=W) lbl_PhoneNumber = Label(ContactForm, text="Phone Number", font=('arial', 14), bd=5) lbl_PhoneNumber.grid(row=6, sticky=W) lbl_Religion = Label(ContactForm, text="Religion", font=('arial', 14), bd=5) lbl_Religion.grid(row=7, sticky=W) lbl_Nationality = Label(ContactForm, text="Nationality", font=('arial', 14), bd=5) lbl_Nationality.grid(row=8, sticky=W) # TEXT ENTRY FirstName = Entry(ContactForm, textvariable=f_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') FirstName.grid(row=0, column=1) MiddleName = Entry(ContactForm, textvariable=m_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') MiddleName.grid(row=1, column=1) LastName = Entry(ContactForm, textvariable=l_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') LastName.grid(row=2, column=1) RadioGroup.grid(row=3, column=1) Age = Entry(ContactForm, textvariable=age, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Age.grid(row=4, column=1) HomeAddress = Entry(ContactForm, textvariable=home_address, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') HomeAddress.grid(row=5, column=1) PhoneNumber = Entry(ContactForm, textvariable=phone_number, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') PhoneNumber.grid(row=6, column=1) Religion = Entry(ContactForm, textvariable=religion, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Religion.grid(row=7, column=1) Nationality = Entry(ContactForm, textvariable=nationality, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Nationality.grid(row=8, column=1) # ==================BUTTONS============================== ButtonUpdatContact = Button(ContactForm, text='Update', bd=10, font=('arial', 12, 'bold'), relief="ridge", fg="white", bg="blue", command=Update) ButtonUpdatContact.grid(row=9, columnspan=2, pady=10) |
When the above code is executed, it produces the following result below.
Output:

This module is for delete function in the database table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
def Delete(): if not tree.selection(): result = tkMessageBox.showwarning('', 'Please Select in the Table First!', icon="warning") else: result = tkMessageBox.askquestion('', 'Are You Sure You Want To Delete This Record?', icon="warning") if result == 'yes': curItem = tree.focus() contents = (tree.item(curItem)) selecteditem = contents['values'] tree.delete(curItem) conn = sqlite3.connect("contactdb.db") cursor = conn.cursor() cursor.execute("DELETE FROM `contactable` WHERE `id` = %d" % selecteditem[0]) conn.commit() cursor.close() conn.close() |
In the code above, This method is used to ask the user about some action to which, the user can answer in yes or no. If yes it will delete the contact record in the table and if no it will remain the contact record in the table . (Contact Management System Project in Python With Source Code)
When the above code is executed, it produces the following result below.
Output:

This module is for the frame, labels, text entry, and button for add new contact form window
1 |
def AddNewContact():<br> global NewWindow<br> f_name.set("")<br> m_name.set("")<br> l_name.set("")<br> gender.set("")<br> age.set("")<br> home_address.set("")<br> phone_number.set("")<br> religion.set("")<br> nationality.set("")<br> NewWindow = Toplevel()<br> NewWindow.title("Contact Details")<br> NewWindow.resizable(0, 0)<br> NewWindow.geometry("500x520+0+0")<br> NewWindow.config(bg="dark gray")<br> if 'UpdateWindow' in globals():<br> UpdateWindow.destroy()<br><br> # ===================FRAMES==============================<br> FormTitle = Frame(NewWindow)<br> FormTitle.pack(side=TOP)<br> ContactForm = Frame(NewWindow)<br> ContactForm.pack(side=TOP, pady=10)<br> RadioGroup = Frame(ContactForm)<br> Male = Radiobutton(RadioGroup, text="Male", variable=gender, value="Male", font=('arial', 14)).pack(side=LEFT)<br> Female = Radiobutton(RadioGroup, text="Female", variable=gender, value="Female", font=('arial', 14)).pack(side=LEFT)<br> Transgender = Radiobutton(RadioGroup, text="Transgender", variable=gender, value="Transgender", font=('arial', 14)).pack(side=LEFT)<br> # ===================LABELS==============================<br> lbl_title = Label(FormTitle, text="Adding New Contacts", bd=12, relief=GROOVE, fg="White", bg="blue",<br> font=("Calibri", 14, "bold"), pady=3)<br> lbl_title.pack(fill=X)<br> lbl_FirstName = Label(ContactForm, text="First Name", font=('arial', 14), bd=5)<br> lbl_FirstName.grid(row=0, sticky=W)<br><br> lbl_MiddleName = Label(ContactForm, text="Middle Name", font=('arial', 14), bd=5)<br> lbl_MiddleName.grid(row=1, sticky=W)<br><br> lbl_LastName = Label(ContactForm, text="Last Name", font=('arial', 14), bd=5)<br> lbl_LastName.grid(row=2, sticky=W)<br><br> lbl_Gender = Label(ContactForm, text="Gender", font=('arial', 14), bd=5)<br> lbl_Gender.grid(row=3, sticky=W)<br><br> lbl_Age = Label(ContactForm, text="Age", font=('arial', 14), bd=5)<br> lbl_Age.grid(row=4, sticky=W)<br><br> lbl_HomeAddress = Label(ContactForm, text=" Home Address", font=('arial', 14), bd=5)<br> lbl_HomeAddress.grid(row=5, sticky=W)<br><br> lbl_PhoneNumber = Label(ContactForm, text="Phone Number", font=('arial', 14), bd=5)<br> lbl_PhoneNumber.grid(row=6, sticky=W)<br><br> lbl_Religion = Label(ContactForm, text="Religion", font=('arial', 14), bd=5)<br> lbl_Religion.grid(row=7, sticky=W)<br><br> lbl_Nationality = Label(ContactForm, text="Nationality", font=('arial', 14), bd=5)<br> lbl_Nationality.grid(row=8, sticky=W)<br><br> # ===================ENTRY===============================<br> FirstName = Entry(ContactForm, textvariable=f_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left')<br> FirstName.grid(row=0, column=1)<br><br> MiddleName = Entry(ContactForm, textvariable=m_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left')<br> MiddleName.grid(row=1, column=1)<br><br> LastName = Entry(ContactForm, textvariable=l_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left')<br> LastName.grid(row=2, column=1)<br><br> RadioGroup.grid(row=3, column=1)<br><br> Age = Entry(ContactForm, textvariable=age, font=('arial', 14, 'bold'), bd=10, width=20, justify='left')<br> Age.grid(row=4, column=1)<br><br> HomeAddress = Entry(ContactForm, textvariable=home_address, font=('arial', 14, 'bold'), bd=10, width=20, justify='left')<br> HomeAddress.grid(row=5, column=1)<br><br> PhoneNumber = Entry(ContactForm, textvariable=phone_number, font=('arial', 14, 'bold'), bd=10, width=20, justify='left')<br> PhoneNumber.grid(row=6, column=1)<br><br> Religion = Entry(ContactForm, textvariable=religion, font=('arial', 14, 'bold'), bd=10, width=20, justify='left')<br> Religion.grid(row=7, column=1)<br><br> Nationality = Entry(ContactForm, textvariable=nationality, font=('arial', 14, 'bold'), bd=10, width=20, justify='left')<br> Nationality.grid(row=8, column=1)<br><br> # ==================BUTTONS==============================<br> ButtonAddContact = Button(ContactForm, text='Save', bd=10, font=('arial', 12, 'bold'), relief="ridge", fg="white",<br> bg="blue", command=Submit)<br> ButtonAddContact.grid(row=9, columnspan=2, pady=10) |
In the code above, This method used for adding a new contact user.
When the above code is executed, it produces the following result below.
Output:

This module is for the whole frame window, labels and button of contact management system
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Top = Frame(root, width=500, bd=1, relief=SOLID) Top.pack(side=TOP) Mid = Frame(root, width=500, bg="dark gray") Mid.pack(side=BOTTOM) f1 = Frame(root, width=6, height=8, bd=8, bg="dark gray") f1.pack(side=BOTTOM) flb = Frame(f1, width=6, height=8, bd=8, bg="blue") flb.pack(side=BOTTOM) MidLeft = Frame(Mid, width=100) MidLeft.pack(side=LEFT, pady=10) MidLeftPadding = Frame(Mid, width=370, bg="dark gray") MidLeftPadding.pack(side=LEFT) MidRight = Frame(Mid, width=100) MidRight.pack(side=RIGHT, pady=10) TableMargin = Frame(root, width=500) TableMargin.pack(side=TOP) # LABELS lbl_title = Label(Top, text="Contact Management System", bd=12, relief=GROOVE, fg="White", bg="blue", font=("Calibri", 36, "bold"), pady=3) lbl_title.pack(fill=X) # BUTTONS ButtonAdd = Button(flb, text='Add New Contact', bd=8, font=('arial', 12, 'bold'), relief="groove", fg="black", bg="dark gray", command=AddNewContact).grid(row=0, column=0, ipadx=20, padx=30) ButtonDelete = Button(flb, text='Delete', bd=8, font=('arial', 12, 'bold'), relief="groove", command=Delete, fg="black", bg="dark gray").grid(row=0, column=1, ipadx=20) ButtonExit = Button(flb, text='Exit System', bd=8, font=('arial', 12, 'bold'), relief="groove", command=Exit, fg="black", bg="dark gray").grid(row=0, column=2, ipadx=20, padx=30) |
This module is for creating a tables in contact management system window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
scrollbarx = Scrollbar(TableMargin, orient=HORIZONTAL) scrollbary = Scrollbar(TableMargin, orient=VERTICAL) tree = ttk.Treeview(TableMargin, columns=("Id", "First Name", "Middle Name", "Last Name", "Gender", "Age", "Home Address", "Phone Number", "Religion", "Nationality"), height=400, selectmode="extended", yscrollcommand=scrollbary.set, xscrollcommand=scrollbarx.set) scrollbary.config(command=tree.yview) scrollbary.pack(side=RIGHT, fill=Y) scrollbarx.config(command=tree.xview) scrollbarx.pack(side=BOTTOM, fill=X) tree.heading('Id', text="Id", anchor=W) tree.heading('First Name', text="First Name", anchor=W) tree.heading('Middle Name', text="Middle Name", anchor=W) tree.heading('Last Name', text="Last Name", anchor=W) tree.heading('Gender', text="Gender", anchor=W) tree.heading('Age', text="Age", anchor=W) tree.heading('Home Address', text="Home Address", anchor=W) tree.heading('Phone Number', text="phone Number", anchor=W) tree.heading('Religion', text="Religion", anchor=W) tree.heading('Nationality', text="Nationality", anchor=W) tree.column('#0', stretch=NO, minwidth=0, width=0) tree.column('#1', stretch=NO, minwidth=0, width=0) tree.column('#2', stretch=NO, minwidth=0, width=80) tree.column('#3', stretch=NO, minwidth=0, width=120) tree.column('#4', stretch=NO, minwidth=0, width=90) tree.column('#5', stretch=NO, minwidth=0, width=80) tree.column('#6', stretch=NO, minwidth=0, width=30) tree.column('#7', stretch=NO, minwidth=0, width=120) tree.column('#8', stretch=NO, minwidth=0, width=120) tree.column('#9', stretch=NO, minwidth=0, width=120) tree.pack() tree.bind('<Double-Button-1>', UpdateContactWindow) |
In the code above, This method will show you how to create a table in contact management system window.
When the above code is executed, it produces the following result below.
Output:

Complete source code of the Contact Management System
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
from tkinter import * import sqlite3 import tkinter import tkinter.ttk as ttk import tkinter.messagebox as tkMessageBox root = Tk() root.title("Contact System") root.geometry("700x400+0+0") root.resizable(0, 0) root.config(bg="dark gray") # VARIABLES f_name = StringVar() m_name = StringVar() l_name = StringVar() age = StringVar() home_address = StringVar() phone_number = StringVar() gender = StringVar() religion = StringVar() nationality = StringVar() # METHODS def Exit(): wayOut = tkinter.messagebox.askyesno("Contact Management System", "Do you want to exit the system") if wayOut > 0: root.destroy() return def Reset(): f_name.set("") m_name.set("") l_name.set("") gender.set("") age.set("") home_address.set("") phone_number.set("") religion.set("") nationality.set("") def Database(): conn = sqlite3.connect("contactdb.db") cursor = conn.cursor() cursor.execute( "CREATE TABLE IF NOT EXISTS `contactable` (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, first_name TEXT, middle_name TEXT, last_name TEXT, gender TEXT, age TEXT, home_address TEXT, phone_number TEXT, religion TEXT, nationality TEXT)") cursor.execute("SELECT * FROM `contactable` ORDER BY `last_name` ASC") fetch = cursor.fetchall() for data in fetch: tree.insert('', 'end', values=(data)) cursor.close() conn.close() def Submit(): if f_name.get() == "" or m_name.get() == "" or l_name.get() == "" or gender.get() == "" or age.get() == "" or home_address.get() == "" or phone_number.get() == "" or religion.get() == "" or nationality.get() == "": result = tkMessageBox.showwarning('', 'Please Complete The Required Field', icon="warning") else: tree.delete(*tree.get_children()) conn = sqlite3.connect("contactdb.db") cursor = conn.cursor() cursor.execute( "INSERT INTO `contactable` (first_name, middle_name, last_name, gender, age, home_address, phone_number, religion, nationality) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", (str(f_name.get()), str(m_name.get()), str(l_name.get()), str(gender.get()), int(age.get()), str(home_address.get()), int(phone_number.get()), str(religion.get()), str(nationality.get()))) conn.commit() cursor.execute("SELECT * FROM `contactable` ORDER BY `last_name` ASC") fetch = cursor.fetchall() for data in fetch: tree.insert('', 'end', values=(data)) cursor.close() conn.close() f_name.set("") m_name.set("") l_name.set("") gender.set("") age.set("") home_address.set("") phone_number.set("") religion.set("") nationality.set("") def Update(): if gender.get() == "": result = tkMessageBox.showwarning('', 'Please Complete The Required Field', icon="warning") else: tree.delete(*tree.get_children()) conn = sqlite3.connect("contactdb.db") cursor = conn.cursor() cursor.execute( "UPDATE `contactable` SET `first_name` = ?, `middle_name` = ? , `last_name` = ?, `gender` =?, `age` = ?, `home_address` = ?, `phone_number` = ?, `religion` = ?, `nationality` = ? WHERE `id` = ?", (str(f_name.get()), str(m_name.get()), str(l_name.get()), str(gender.get()), int(age.get()), str(home_address.get()), str(phone_number.get()), str(religion.get()), str(nationality.get()), int(id))) conn.commit() cursor.execute("SELECT * FROM `contactable` ORDER BY `last_name` ASC") fetch = cursor.fetchall() for data in fetch: tree.insert('', 'end', values=(data)) cursor.close() conn.close() f_name.set("") m_name.set("") l_name.set("") gender.set("") age.set("") home_address.set("") phone_number.set("") religion.set("") nationality.set("") def UpdateContactWindow(event): global id, UpdateWindow curItem = tree.focus() contents = (tree.item(curItem)) selecteditem = contents['values'] id = selecteditem[0] f_name.set("") m_name.set("") l_name.set("") gender.set("") age.set("") home_address.set("") phone_number.set("") religion.set("") nationality.set("") f_name.set(selecteditem[1]) m_name.set(selecteditem[2]) l_name.set(selecteditem[3]) age.set(selecteditem[5]) home_address.set(selecteditem[6]) phone_number.set(selecteditem[7]) religion.set(selecteditem[8]) nationality.set(selecteditem[9]) UpdateWindow = Toplevel() UpdateWindow.title("Contact Details") UpdateWindow.geometry("500x520+0+0") UpdateWindow.config(bg="dark gray") UpdateWindow.resizable(0, 0) if 'NewWindow' in globals(): NewWindow.destroy() # FRAMES FormTitle = Frame(UpdateWindow) FormTitle.pack(side=TOP) ContactForm = Frame(UpdateWindow) ContactForm.pack(side=TOP, pady=10) RadioGroup = Frame(ContactForm) Male = Radiobutton(RadioGroup, text="Male", variable=gender, value="Male", font=('arial', 14)).pack(side=LEFT) Female = Radiobutton(RadioGroup, text="Female", variable=gender, value="Female", font=('arial', 14)).pack(side=LEFT) Transgender = Radiobutton(RadioGroup, text="Transgender", variable=gender, value="Transgender", font=('arial', 14)).pack(side=LEFT) # LABELS lbl_title = Label(FormTitle, text="Updating Contacts", font=('arial', 16), bg="blue", width=300) lbl_title.pack(fill=X) lbl_FirstName = Label(ContactForm, text="First Name", font=('arial', 14), bd=5) lbl_FirstName.grid(row=0, sticky=W) lbl_MiddleName = Label(ContactForm, text="Middle Name", font=('arial', 14), bd=5) lbl_MiddleName.grid(row=1, sticky=W) lbl_LastName = Label(ContactForm, text="Last Name", font=('arial', 14), bd=5) lbl_LastName.grid(row=2, sticky=W) lbl_Gender = Label(ContactForm, text="Gender", font=('arial', 14), bd=5) lbl_Gender.grid(row=3, sticky=W) lbl_Age = Label(ContactForm, text="Age", font=('arial', 14), bd=5) lbl_Age.grid(row=4, sticky=W) lbl_HomeAddress = Label(ContactForm, text=" Home Address", font=('arial', 14), bd=5) lbl_HomeAddress.grid(row=5, sticky=W) lbl_PhoneNumber = Label(ContactForm, text="Phone Number", font=('arial', 14), bd=5) lbl_PhoneNumber.grid(row=6, sticky=W) lbl_Religion = Label(ContactForm, text="Religion", font=('arial', 14), bd=5) lbl_Religion.grid(row=7, sticky=W) lbl_Nationality = Label(ContactForm, text="Nationality", font=('arial', 14), bd=5) lbl_Nationality.grid(row=8, sticky=W) # TEXT ENTRY FirstName = Entry(ContactForm, textvariable=f_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') FirstName.grid(row=0, column=1) MiddleName = Entry(ContactForm, textvariable=m_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') MiddleName.grid(row=1, column=1) LastName = Entry(ContactForm, textvariable=l_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') LastName.grid(row=2, column=1) RadioGroup.grid(row=3, column=1) Age = Entry(ContactForm, textvariable=age, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Age.grid(row=4, column=1) HomeAddress = Entry(ContactForm, textvariable=home_address, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') HomeAddress.grid(row=5, column=1) PhoneNumber = Entry(ContactForm, textvariable=phone_number, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') PhoneNumber.grid(row=6, column=1) Religion = Entry(ContactForm, textvariable=religion, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Religion.grid(row=7, column=1) Nationality = Entry(ContactForm, textvariable=nationality, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Nationality.grid(row=8, column=1) # ==================BUTTONS============================== ButtonUpdatContact = Button(ContactForm, text='Update', bd=10, font=('arial', 12, 'bold'), relief="ridge", fg="white", bg="blue", command=Update) ButtonUpdatContact.grid(row=9, columnspan=2, pady=10) def Delete(): if not tree.selection(): result = tkMessageBox.showwarning('', 'Please Select in the Table First!', icon="warning") else: result = tkMessageBox.askquestion('', 'Are You Sure You Want To Delete This Record?', icon="warning") if result == 'yes': curItem = tree.focus() contents = (tree.item(curItem)) selecteditem = contents['values'] tree.delete(curItem) conn = sqlite3.connect("contactdb.db") cursor = conn.cursor() cursor.execute("DELETE FROM `contactable` WHERE `id` = %d" % selecteditem[0]) conn.commit() cursor.close() conn.close() def AddNewContact(): global NewWindow f_name.set("") m_name.set("") l_name.set("") gender.set("") age.set("") home_address.set("") phone_number.set("") religion.set("") nationality.set("") NewWindow = Toplevel() NewWindow.title("Contact Details") NewWindow.resizable(0, 0) NewWindow.geometry("500x520+0+0") NewWindow.config(bg="dark gray") if 'UpdateWindow' in globals(): UpdateWindow.destroy() # ===================FRAMES============================== FormTitle = Frame(NewWindow) FormTitle.pack(side=TOP) ContactForm = Frame(NewWindow) ContactForm.pack(side=TOP, pady=10) RadioGroup = Frame(ContactForm) Male = Radiobutton(RadioGroup, text="Male", variable=gender, value="Male", font=('arial', 14)).pack(side=LEFT) Female = Radiobutton(RadioGroup, text="Female", variable=gender, value="Female", font=('arial', 14)).pack(side=LEFT) Transgender = Radiobutton(RadioGroup, text="Transgender", variable=gender, value="Transgender", font=('arial', 14)).pack(side=LEFT) # ===================LABELS============================== lbl_title = Label(FormTitle, text="Adding New Contacts", bd=12, relief=GROOVE, fg="White", bg="blue", font=("Calibri", 14, "bold"), pady=3) lbl_title.pack(fill=X) lbl_FirstName = Label(ContactForm, text="First Name", font=('arial', 14), bd=5) lbl_FirstName.grid(row=0, sticky=W) lbl_MiddleName = Label(ContactForm, text="Middle Name", font=('arial', 14), bd=5) lbl_MiddleName.grid(row=1, sticky=W) lbl_LastName = Label(ContactForm, text="Last Name", font=('arial', 14), bd=5) lbl_LastName.grid(row=2, sticky=W) lbl_Gender = Label(ContactForm, text="Gender", font=('arial', 14), bd=5) lbl_Gender.grid(row=3, sticky=W) lbl_Age = Label(ContactForm, text="Age", font=('arial', 14), bd=5) lbl_Age.grid(row=4, sticky=W) lbl_HomeAddress = Label(ContactForm, text=" Home Address", font=('arial', 14), bd=5) lbl_HomeAddress.grid(row=5, sticky=W) lbl_PhoneNumber = Label(ContactForm, text="Phone Number", font=('arial', 14), bd=5) lbl_PhoneNumber.grid(row=6, sticky=W) lbl_Religion = Label(ContactForm, text="Religion", font=('arial', 14), bd=5) lbl_Religion.grid(row=7, sticky=W) lbl_Nationality = Label(ContactForm, text="Nationality", font=('arial', 14), bd=5) lbl_Nationality.grid(row=8, sticky=W) # ===================ENTRY=============================== FirstName = Entry(ContactForm, textvariable=f_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') FirstName.grid(row=0, column=1) MiddleName = Entry(ContactForm, textvariable=m_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') MiddleName.grid(row=1, column=1) LastName = Entry(ContactForm, textvariable=l_name, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') LastName.grid(row=2, column=1) RadioGroup.grid(row=3, column=1) Age = Entry(ContactForm, textvariable=age, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Age.grid(row=4, column=1) HomeAddress = Entry(ContactForm, textvariable=home_address, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') HomeAddress.grid(row=5, column=1) PhoneNumber = Entry(ContactForm, textvariable=phone_number, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') PhoneNumber.grid(row=6, column=1) Religion = Entry(ContactForm, textvariable=religion, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Religion.grid(row=7, column=1) Nationality = Entry(ContactForm, textvariable=nationality, font=('arial', 14, 'bold'), bd=10, width=20, justify='left') Nationality.grid(row=8, column=1) # ==================BUTTONS============================== ButtonAddContact = Button(ContactForm, text='Save', bd=10, font=('arial', 12, 'bold'), relief="ridge", fg="white", bg="blue", command=Submit) ButtonAddContact.grid(row=9, columnspan=2, pady=10) # ============================FRAMES====================================== Top = Frame(root, width=500, bd=1, relief=SOLID) Top.pack(side=TOP) Mid = Frame(root, width=500, bg="dark gray") Mid.pack(side=BOTTOM) f1 = Frame(root, width=6, height=8, bd=8, bg="dark gray") f1.pack(side=BOTTOM) flb = Frame(f1, width=6, height=8, bd=8, bg="blue") flb.pack(side=BOTTOM) MidLeft = Frame(Mid, width=100) MidLeft.pack(side=LEFT, pady=10) MidLeftPadding = Frame(Mid, width=370, bg="dark gray") MidLeftPadding.pack(side=LEFT) MidRight = Frame(Mid, width=100) MidRight.pack(side=RIGHT, pady=10) TableMargin = Frame(root, width=500) TableMargin.pack(side=TOP) # LABELS lbl_title = Label(Top, text="Contact Management System", bd=12, relief=GROOVE, fg="White", bg="blue", font=("Calibri", 36, "bold"), pady=3) lbl_title.pack(fill=X) # BUTTONS ButtonAdd = Button(flb, text='Add New Contact', bd=8, font=('arial', 12, 'bold'), relief="groove", fg="black", bg="dark gray", command=AddNewContact).grid(row=0, column=0, ipadx=20, padx=30) ButtonDelete = Button(flb, text='Delete', bd=8, font=('arial', 12, 'bold'), relief="groove", command=Delete, fg="black", bg="dark gray").grid(row=0, column=1, ipadx=20) ButtonExit = Button(flb, text='Exit System', bd=8, font=('arial', 12, 'bold'), relief="groove", command=Exit, fg="black", bg="dark gray").grid(row=0, column=2, ipadx=20, padx=30) # TABLES scrollbarx = Scrollbar(TableMargin, orient=HORIZONTAL) scrollbary = Scrollbar(TableMargin, orient=VERTICAL) tree = ttk.Treeview(TableMargin, columns=("Id", "First Name", "Middle Name", "Last Name", "Gender", "Age", "Home Address", "Phone Number", "Religion", "Nationality"), height=400, selectmode="extended", yscrollcommand=scrollbary.set, xscrollcommand=scrollbarx.set) scrollbary.config(command=tree.yview) scrollbary.pack(side=RIGHT, fill=Y) scrollbarx.config(command=tree.xview) scrollbarx.pack(side=BOTTOM, fill=X) tree.heading('Id', text="Id", anchor=W) tree.heading('First Name', text="First Name", anchor=W) tree.heading('Middle Name', text="Middle Name", anchor=W) tree.heading('Last Name', text="Last Name", anchor=W) tree.heading('Gender', text="Gender", anchor=W) tree.heading('Age', text="Age", anchor=W) tree.heading('Home Address', text="Home Address", anchor=W) tree.heading('Phone Number', text="phone Number", anchor=W) tree.heading('Religion', text="Religion", anchor=W) tree.heading('Nationality', text="Nationality", anchor=W) tree.column('#0', stretch=NO, minwidth=0, width=0) tree.column('#1', stretch=NO, minwidth=0, width=0) tree.column('#2', stretch=NO, minwidth=0, width=80) tree.column('#3', stretch=NO, minwidth=0, width=120) tree.column('#4', stretch=NO, minwidth=0, width=90) tree.column('#5', stretch=NO, minwidth=0, width=80) tree.column('#6', stretch=NO, minwidth=0, width=30) tree.column('#7', stretch=NO, minwidth=0, width=120) tree.column('#8', stretch=NO, minwidth=0, width=120) tree.column('#9', stretch=NO, minwidth=0, width=120) tree.pack() tree.bind('<Double-Button-1>', UpdateContactWindow) # ============================INITIALIZATION============================== if __name__ == '__main__': Database() root.mainloop() |
Output:

How To Run The Contact Management System Project in Python With Source Code?
To run this project, you must have installed a Pycharm on your PC (for Windows). This Contact Management System Project in Python With Source Code is free to download, Use for educational purposes only!
After downloading the project you must follow the steps below:
Step 1: Unzip the file or Extract the file
Step 2: Double click the Contact-System
Step 3: Project is ready to run
Run Quick Virus Scan for secure Download
Run Quick Scan for safe DownloadDownloadable Source Code
I have here the list of Best Python Project with Source code free to download for free, I hope this can help you a lot.
Conclusion:
The Contact Management System Project in Python is a easy graphical user interface based mission which may be very comprehensible and utilizes. Speaking about the system, it consists of all the referred to as for features that consist of adding, viewing, doing away with and additionally upgrading contact lists. While including the call of a person, he/she has to provide given name,middle name, last name, gender, age, home address, religion, nationality cope with and make contact with information.
Related Article Below
- Hotel Management System Project in Python With Source Code
- Student Management System Project in Python with Source Code
- How To Make A Point Of Sale System In Python
- Best Python Projects for Beginners
- Python MySQL Connection: Simple Python Step by Step Guide
- Python PIP Command Set-up / Fix: Step by Step Guide
- Random Password Generator in Python Projects With Source Code 2020
- Python Range Function|Range in Python Explained with Examples 2020
- Billing System Project in Python Project With Source Code
- Employee Payment Management System Project in Python
- School Management System Project In Python With Source Code
- Bank Management System Project in Python With Source Code
Inquiries
If you have any questions or suggestions about Contact Management System Project in Python With Source Code , please feel free to leave a comment below.