
Phonebook GUI Application Made With Python and Tkinter (Part V).
I am a newbie on the programming world and I am trying to learn Python as it is the easiest and very strong programming language. I've learnt all basic theories and the programming syntax and then I have solved some problems from urionlinejudge. Now I'am trying to learn GUI Appliations and I am trying to learn Tkinter module of Python.
Previously I posted a Restaurant Management System GUI application that I made with Python and Tkinter module of python. Here is Phonebook GUI Application Made With Python and Tkinter. I will post the code into different parts. This is the third part.
First Part
Second Part
Third Part
Fourth Part
Let us jump to the codes of "display_people.py".
Importing
import tkinter as tk
import _sqlite3
from tkinter import PhotoImage
import datetime
date = datetime.datetime.now().date()
date = str(date)
con = _sqlite3.connect('database.db')
cur = con.cursor()
Class "Display_people"
class Display_people(tk.Toplevel):
def __init__(self, person_id):
tk.Toplevel.__init__(self)
self.geometry('650x550+380+80')
self.title('My People')
self.resizable(0,0)
self.top = tk.Frame(self, height=150, bg='white')
self.top.pack(fill=tk.X)
self.bottom = tk.Frame(self, height=500, bg='#ebb134')
self.bottom.pack(fill=tk.X)
# ---------- icon ------------
self.top_image = PhotoImage(file='icons/people.png')
self.top_image_label = tk.Label(self.top, image=self.top_image, bg='white')
self.top_image_label.place(x=130, y=25)
# -------------------- heading ----------------
self.heading = tk.Label(self.top, text='Person Details', bg='white', font='arial 15 bold', fg='#34baeb')
self.heading.place(x=230, y=40)
# ------------------------ date -------------------------------
self.date_lbl = tk.Label(self.top, text=f'Date: {date}', font='arial 11 bold', bg='white', fg='#ebb434')
self.date_lbl.place(x=500, y=10)
# ------------- query -----------------------
query = 'select * from "addressbook" where person_id = {}'.format(person_id)
result = cur.execute(query).fetchone()
self.person_id = person_id
person_name = result[1]
person_surname = result[2]
email = result[3]
phone = result[4]
address = result[5]
# name
self.label_name = tk.Label(self.bottom, text='Name: ', font='Arial 12 bold', bg='#ebb134')
self.label_name.place(x=40, y=40)
self.entry_name = tk.Entry(self.bottom, width=30, bd=4)
self.entry_name.insert(0, person_name)
self.entry_name.config(state='disabled')
self.entry_name.place(x=175, y=40)
# surname
self.label_surname = tk.Label(self.bottom, text='Surname: ', font='Arial 12 bold', bg='#ebb134')
self.label_surname.place(x=40, y=80)
self.entry_surname = tk.Entry(self.bottom, width=30, bd=4)
self.entry_surname.insert(0, person_surname)
self.entry_surname.config(state='disabled')
self.entry_surname.place(x=175, y=80)
# email
self.label_email = tk.Label(self.bottom, text='Email: ', font='Arial 12 bold', bg='#ebb134')
self.label_email.place(x=40, y=120)
self.entry_email = tk.Entry(self.bottom, width=30, bd=4)
self.entry_email.insert(0, email)
self.entry_email.config(state='disabled')
self.entry_email.place(x=175, y=120)
# phone number
self.label_phone = tk.Label(self.bottom, text='Phone Number: ', font='Arial 12 bold', bg='#ebb134')
self.label_phone.place(x=40, y=160)
self.entry_phone = tk.Entry(self.bottom, width=30, bd=4)
self.entry_phone.insert(0, phone)
self.entry_phone.config(state='disabled')
self.entry_phone.place(x=175, y=160)
# address
self.label_Address = tk.Label(self.bottom, text='Address: ', font='Arial 12 bold', bg='#ebb134')
self.label_Address.place(x=40, y=200)
self.entry_Address = tk.Text(self.bottom, width=24, height=3, wrap='word')
self.entry_Address.insert(1.0, address)
self.entry_Address.config(state='disabled')
self.entry_Address.place(x=175, y=200)
So the full codes of "display_people.py" is :-
import tkinter as tk
import _sqlite3
from tkinter import PhotoImage
import datetime
date = datetime.datetime.now().date()
date = str(date)
con = _sqlite3.connect('database.db')
cur = con.cursor()
class Display_people(tk.Toplevel):
def __init__(self, person_id):
tk.Toplevel.__init__(self)
self.geometry('650x550+380+80')
self.title('My People')
self.resizable(0,0)
self.top = tk.Frame(self, height=150, bg='white')
self.top.pack(fill=tk.X)
self.bottom = tk.Frame(self, height=500, bg='#ebb134')
self.bottom.pack(fill=tk.X)
# ---------- icon ------------
self.top_image = PhotoImage(file='icons/people.png')
self.top_image_label = tk.Label(self.top, image=self.top_image, bg='white')
self.top_image_label.place(x=130, y=25)
# -------------------- heading ----------------
self.heading = tk.Label(self.top, text='Person Details', bg='white', font='arial 15 bold', fg='#34baeb')
self.heading.place(x=230, y=40)
# ------------------------ date -------------------------------
self.date_lbl = tk.Label(self.top, text=f'Date: {date}', font='arial 11 bold', bg='white', fg='#ebb434')
self.date_lbl.place(x=500, y=10)
# ------------- query -----------------------
query = 'select * from "addressbook" where person_id = {}'.format(person_id)
result = cur.execute(query).fetchone()
self.person_id = person_id
person_name = result[1]
person_surname = result[2]
email = result[3]
phone = result[4]
address = result[5]
# name
self.label_name = tk.Label(self.bottom, text='Name: ', font='Arial 12 bold', bg='#ebb134')
self.label_name.place(x=40, y=40)
self.entry_name = tk.Entry(self.bottom, width=30, bd=4)
self.entry_name.insert(0, person_name)
self.entry_name.config(state='disabled')
self.entry_name.place(x=175, y=40)
# surname
self.label_surname = tk.Label(self.bottom, text='Surname: ', font='Arial 12 bold', bg='#ebb134')
self.label_surname.place(x=40, y=80)
self.entry_surname = tk.Entry(self.bottom, width=30, bd=4)
self.entry_surname.insert(0, person_surname)
self.entry_surname.config(state='disabled')
self.entry_surname.place(x=175, y=80)
# email
self.label_email = tk.Label(self.bottom, text='Email: ', font='Arial 12 bold', bg='#ebb134')
self.label_email.place(x=40, y=120)
self.entry_email = tk.Entry(self.bottom, width=30, bd=4)
self.entry_email.insert(0, email)
self.entry_email.config(state='disabled')
self.entry_email.place(x=175, y=120)
# phone number
self.label_phone = tk.Label(self.bottom, text='Phone Number: ', font='Arial 12 bold', bg='#ebb134')
self.label_phone.place(x=40, y=160)
self.entry_phone = tk.Entry(self.bottom, width=30, bd=4)
self.entry_phone.insert(0, phone)
self.entry_phone.config(state='disabled')
self.entry_phone.place(x=175, y=160)
# address
self.label_Address = tk.Label(self.bottom, text='Address: ', font='Arial 12 bold', bg='#ebb134')
self.label_Address.place(x=40, y=200)
self.entry_Address = tk.Text(self.bottom, width=24, height=3, wrap='word')
self.entry_Address.insert(1.0, address)
self.entry_Address.config(state='disabled')
self.entry_Address.place(x=175, y=200)
And this is the final part of the project. Thank you.
Leave Phonebook GUI Application Made With Python and Tkinter (Part V). to:
Read more #programming posts
Best Posts From here-to-share
We have not curated any of here-to-share's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From here-to-share
- Digital Drawing of the XANDER FOXWOOD. Drawing Using Autodesk.
- Agency Website Frontpage Design. Part III.
- My First Drawing. Fan-Art of TARSA From Splinterlands Cards.
- Agency Website Frontpage Design. Part II.
- Agency Website Frontpage Design. Part I.
- Random Jokes Using AJAX.
- Phonebook GUI Application Made With Python and Tkinter (Part V).
- Phonebook GUI Application Made With Python and Tkinter (Part IV).
- Phonebook GUI Application Made With Python and Tkinter (Part III).
- Phonebook GUI Application Made With Python and Tkinter (Part II).