Programming

Build a Simple Age Calculator Desktop App with Python and Tkinter

Learn how to create a desktop application using Python and Tkinter to easily calculate the age of a person. Follow this step-by-step guide to build a straightforward Age Calculator app with a graphical user interface. Get started with coding and enhance your Python skills today!

Python Code

import tkinter as tk

from datetime import datetime

def calculate_age():

    birth_year = int(entry_birth_year.get())

    current_year = datetime.now().year

    age = current_year - birth_year

    label_result.config(text=f"Your age is: {age} years")

# Create the main window

window = tk.Tk()

window.title("Age Calculator App")

# Create and place widgets (labels, entry, button)

label_instruction = tk.Label(window, text="Enter your birth year:")

label_instruction.pack(pady=10)

entry_birth_year = tk.Entry(window)

entry_birth_year.pack(pady=10)

button_calculate = tk.Button(window, text="Calculate Age", command=calculate_age)

button_calculate.pack(pady=10)

label_result = tk.Label(window, text="")

label_result.pack(pady=10)

# Run the application

window.mainloop()

 

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.