Python Tkinter GUI Script to Make a Simple Age Calculator From Date of Birth (DOB) Full Project For Beginners

Python Tkinter GUI Script to Make a Simple Age Calculator From Date of Birth (DOB) Full Project For Beginners

 

Welcome folks today in this blog post we will be making a simple age calculator in python and we will be making a GUI Program using tkinter. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to install tkinter library by executing the npm command

 

pip install tkinter

 

After installing the library just make an app.py file and copy paste the following code

 

app.py

 

from tkinter import *
from datetime import date
root = Tk()
root.geometry("700x500")
root.title("Age Calculator")

def calculateAge():
    today = date.today()
    birthDate = date(int(yearEntry.get()), int(monthEntry.get()), int(dayEntry.get()))
    age = today.year - birthDate.year - ((today.month, today.day) < (birthDate.month, birthDate.day))
    Label(text=f"{nameValue.get()} your age is {age}").grid(row=6, column=1)
    
Label(text="Name").grid(row=1, column=0, padx=90)
Label(text="Year").grid(row=2, column=0)
Label(text="Month").grid(row=3, column=0)
Label(text="Day").grid(row=4, column=0)

nameValue = StringVar()
yearValue = StringVar()
monthValue = StringVar()
dayValue = StringVar()

nameEntry = Entry(root, textvariable=nameValue)
yearEntry = Entry(root, textvariable=yearValue)
monthEntry = Entry(root, textvariable=monthValue)
dayEntry = Entry(root, textvariable=dayValue)

nameEntry.grid(row=1, column=1, pady=10)
yearEntry.grid(row=2, column=1, pady=10)
monthEntry.grid(row=3, column=1, pady=10)
dayEntry.grid(row=4, column=1, pady=10)

computeButton = Button(text="CalculateAge", command=calculateAge)
computeButton.grid(row=5, column=1, pady=10)
root.mainloop()

 

See also  Python 3 MySQL Database Tkinter Student or College Marks Calculator Management System GUI Desktop App Full Project For Beginners

 

Now we will run the python script by executing the below command

 

python app.py

 

 

 

Leave a Reply