Age calculator using Tkinter in python

The Age calculator is a straight forward graphical user interface program crafted using Tkinter, which is a common python library utilized for developing GUI applications. This application empowers users to compute their age by providing their birth date as input.

The following code works for calculating age.

 

import tkinter as tk
from datetime import datetime

def cal_age():
    birth_date = datetime(2000, 1, 1)  
    current_date = datetime.now()
    age = current_date.year - birth_date.year - ((current_date.month, current_date.day) < (birth_date.month, birth_date.day))
    result_label.config(text=f"You are {age} years old.")

root = tk.Tk()
root.title("Age Calculator")

cal_button = tk.Button(root, text="Calculate Age", command=cal_age)
cal_button.pack()

result_label = tk.Label(root, text="")
result_label.pack()

cal_age() 
root.mainloop()

 

Leave a Comment

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

Scroll to Top