Skip to main content

Posts

Showing posts from February, 2025

Python GUI Program to Calculate Age

Python GUI Program to Calculate Age     Certainly! Below is a Python program using the tkinter library to create a simple GUI that accepts a date of birth and calculates the age.   import tkinter as tk from tkinter import messagebox from datetime import datetime def calculate_age():     dob_str = entry_dob.get()     try:         dob = datetime.strptime(dob_str, "%Y-%m-%d")         today = datetime.today()         age = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))         messagebox.showinfo("Age Calculator", f"Your age is: {age} years")     except ValueError:         messagebox.showerror("Error", "Please enter the date in YYYY-MM-DD format") # Create the main window root = tk.Tk() root.title("Age Calculator") # Create a labe...

Python Calculator Program with GUI Intercface

   Python Calculator Program with GUI Intercface Here is a Python program using the tkinter library to create a simple GUI-based calculator. This calculator can perform basic arithmetic operations like addition, subtraction, multiplication, and division.   import tkinter as tk # Function to update the input field when a button is clicked def button_click(item):     global expression     expression = expression + str(item)     input_text.set(expression) # Function to clear the input field def button_clear():     global expression     expression = ""     input_text.set("") # Function to evaluate the expression and display the result def button_equal():     global expression     try:         result = str(eval(expression))  # Evaluate the expression         input_text.set(result) ...