Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Age Calculator in Python with Source Code - Age Calculator in Python

Age Calculator in Python with Source Code

Posted on December 25, 2024December 25, 2024 By Rishabh saini No Comments on Age Calculator in Python with Source Code

Age Calculator in Python

Calculating your age might seem simple, but when done programmatically, it opens the door to learning some useful Python libraries and GUI development. Today, let’s walk through creating a simple age calculator using Python and Tkinter, with a professional and user-friendly touch.

Age Calculator in Python
Simple Age Calculator in Python

  • GUI programming using the Tkinter library.
  • Working with date and time using Python’s datetime module.
  • Enhancing problem-solving skills while making a functional program.

Download New Real Time Projects :-Click here

The Complete Code

Here’s the code for our age calculator:

#importing modules
from tkinter import *
from datetime import date

# Creating the main window
root = Tk()
root.title("AGE-CALCULATOR")   # Setting up the title
root.configure(bg="#D5C6FF")   # Setting up background color
root.geometry("400x300")       # Fixing the size of the window

# Label for displaying results
new = Label(root, bg="#D5C6FF")
new.grid(row=5, column=0, columnspan=3)

# Getting today's date
today = str(date.today())
list_today = today.split("-")

# Function to calculate age
def age(b_date, b_month, b_year):
    global today
    global new
    new.grid_forget()
    b_date = int(entry_date.get())
    b_month = int(entry_month.get())
    b_year = int(entry_year.get())
    c_date = int(list_today[2])
    c_month = int(list_today[1])
    c_year = int(list_today[0])
    month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    if b_date > c_date:
        c_month -= 1
        c_date += month[b_month - 1]
    if b_month > c_month:
        c_year -= 1
        c_month += 12
    resultd = str(c_date - b_date)
    resultm = str(c_month - b_month)
    resulty = str(c_year - b_year)
    new = Label(root, text=f"YOUR AGE\n{resulty} YEARS {resultm} MONTHS {resultd} DAYS",
                fg="#990099", bg="#D5C6FF", borderwidth=6)
    new.config(font=("Arial Rounded MT Bold", 15))
    new.grid(row=5, column=0, columnspan=3)

# Function to clear input fields
def clean(entry_date, entry_month, entry_year):
    global new
    new.grid_forget()
    entry_date.delete(0, END)
    entry_month.delete(0, END)
    entry_year.delete(0, END)

# GUI widgets and layout
title_label = Label(root, text="AGE CALCULATOR", borderwidth=10, fg="#6600CC", bg="#D5C6FF")
title_label.config(font=("Broadway", 29))
title_label.grid(row=0, column=0, columnspan=3)

label_date = Label(root, text="BIRTH DATE:", borderwidth=4, fg="#990099", bg="#D5C6FF")
label_date.config(font=("Arial Rounded MT Bold", 15))
label_date.grid(row=1, column=0)

label_month = Label(root, text="BIRTH MONTH:", borderwidth=5, fg="#990099", bg="#D5C6FF")
label_month.config(font=("Arial Rounded MT Bold", 15))
label_month.grid(row=2, column=0)

label_year = Label(root, text="BIRTH YEAR:", borderwidth=9, fg="#990099", bg="#D5C6FF")
label_year.config(font=("Arial Rounded MT Bold", 15))
label_year.grid(row=3, column=0)

entry_date = Entry(root, width=20, borderwidth=3)
entry_month = Entry(root, width=20, borderwidth=3)
entry_year = Entry(root, width=20, borderwidth=3)

entry_date.grid(row=1, column=2)
entry_month.grid(row=2, column=2)
entry_year.grid(row=3, column=2)

submit = Button(root, text="GET AGE!!", width=10, anchor=CENTER, 
                command=lambda: age(entry_date, entry_month, entry_year), bg="#6600CC", fg="#D5C6FF", borderwidth=5)
submit.grid(row=4, column=0)

clear = Button(root, text="CLEAR", width=10, 
               command=lambda: clean(entry_date, entry_month, entry_year), bg="#6600CC", fg="#D5C6FF", borderwidth=5)
clear.grid(row=4, column=2)

root.mainloop()

Age Calculator in Python
Simple Age Calculator in Python

How It Works

  1. Modules:
    • tkinter for GUI elements.
    • datetime.date to fetch the current date.
  2. UI Design:
    • A simple window with input fields for date, month, and year of birth.
    • Two buttons: GET AGE!! to calculate and CLEAR to reset inputs.
  3. Logic:
    • Fetch the user’s input and the current date.
    • Compare the input date with the current date to compute the difference in years, months, and days.
    • Handle scenarios where the birth date or month exceeds the current date or month.

PHP PROJECT:- CLICK HERE

Key Features

  • User-friendly Interface: The application is designed with a clean, minimalistic layout.
  • Error Handling: Ensures accurate calculations even when days and months exceed usual limits.
  • Interactive and Fun: Instant results displayed with a vibrant and engaging design.


age calculator in python with source code
python program to calculate age in years, months and days
age calculator in python tkinter
age calculator in python with source code
python calculate age from date of birth dataframe
python program to display age is greater than 18 or not
age calculator project report pdf in python
age calculator in python with source code
python age limit
how to calculate average age in python
python compiler
age calculator
python code for date of birth
Age Calculator in Python with Source Code

Post Views: 1,143
Python Tags:age calculator, age calculator in python, age calculator using python, calculate age in python, calculate age in python pandas, create age calculator in python, how to calculate age in python, make age calculator in python, Python, python age calculator, python calculator, python for beginners, python program to calculate age in years, python programming, python tkinter age calculator, Python Tutorial, tkinter age calculator

Post navigation

Previous Post: AI in Web Development
Next Post: Join Operations in SQL with Python

More Related Articles

Basic I/O Operations in Python Chapter 5 : Basic I/O operations Python
Creating New Databases in MySQL Using Python - Creating New Database  Creating New Databases in MySQL Using Python Python
Exploring Python IDEs: A Guide to Popular Development Environments - Exploring Python IDEs Exploring Python IDEs: A Guide to Popular Development Environments Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. Python Decorators: A Comprehensive Guide
  2. How to Calculate Distance between Two Points using GEOPY
  3. Rock, Paper, Scissors Game
  4. Fetcher App Using Python and Tkinter
  5. How to Install Django: Step-by-Step Guide
  6. Python Tkinter Canvas: A Guide to Structured Graphics in Python

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,615)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,218)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,872)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme