# GUI Age Calculator

Hello friends, today we will make an age calculator using python’s GUI library tkinter so, let’s start.

Python offers a very good GUI library i.e. tkinter which is very easy to learn and use.

Here, we are creating a GUI application to calculate age using a button.

We will ask the user to enter the name and date of birth.

Then we will get that information from the entry widgets and will calculate the user’s age.

At last, we will show the user’s age with the name.

We will use `"calculateAge()"` function to calculate the age of the user.

So, let’s understand the code now.

## Code

```# importing the tkinter module
from tkinter import *

# importing date class from datetime module
from datetime import date

# initializing tkinter
root = Tk()

# setting the width and height of gui
root.geometry("700x500")

# setting the title of gui
root.title("Age Calculator")

photo = PhotoImage(file="filename.png")

# creating a Label widget to show the image we load
myimage = Label(image=photo)

# placing the image Label widget using grid method
myimage.grid(row=0, column=1)

# defining function to calculate age according to the data given
# by the user
def calculateAge():
# storing today's date in "today" variable
today = date.today()
# getting birthdate using .get() method
birthDate = date(int(yearEntry.get()), int(monthEntry.get()), int(dayEntry.get()))
# calculating age by subtracting birthdate from today's date
age = today.year - birthDate.year - ((today.month, today.day) < (birthDate.month, birthDate.day))
# creating a Label widget to show the calculated age using
# grid method
Label(text=f"{nameValue.get()} your age is {age}").grid(row=6, column=1)

# creating a label widget for asking user his/her name

# creating a label widget for asking user his/her year of birth
Label(text="Year").grid(row=2, column=0)

# creating a label widget for asking user his/her month of birth
Label(text="Month").grid(row=3, column=0)

# creating a label widget for asking user his/her day of birth
Label(text="Day").grid(row=4, column=0)

# declaring a variable of string datatype to store the name value
# entered by the user
nameValue = StringVar()

# declaring a variable of string datatype to store the year value
# entered by the user
yearValue = StringVar()

# declaring a variable of string datatype to store the month
# value entered by the user
monthValue = StringVar()

# declaring a variable of string datatype to store the day value
# entered by the user
dayValue = StringVar()

# creating an entry widget to take name value
nameEntry = Entry(root, textvariable=nameValue)

# creating an entry widget to take year value
yearEntry = Entry(root, textvariable=yearValue)

# creating an entry widget to take month value
monthEntry = Entry(root, textvariable=monthValue)

# creating an entry widget to take day value
dayEntry = Entry(root, textvariable=dayValue)

# placing the entry widgets

# creating and placing a button to calculate a show age on
# clicking on this button

# mainloop() is an infinite loop used to run the application when