Programming Examples

Tkinter program to calculate the simple intrest


Python GUI Simple Interest Calculator

Solution

import tkinter as tk
from tkinter import messagebox

def calculate_simple_interest():
    try:
        principal = float(principal_entry.get())
        rate = float(rate_entry.get())
        time = float(time_entry.get())

        # Calculate simple interest
        simple_interest = (principal * rate * time) / 100

        # Display the result
        result_label.config(text=f"Simple Interest: {simple_interest:.2f} USD")

    except ValueError:
        messagebox.showerror("Error", "Please enter valid numeric values for all fields.")

# Create the main window
root = tk.Tk()
root.title("Simple Interest Calculator")

# Create and place widgets
principal_label = tk.Label(root, text="Principal Amount:")
principal_label.pack()

principal_entry = tk.Entry(root)
principal_entry.pack()

rate_label = tk.Label(root, text="Interest Rate (%):")
rate_label.pack()

rate_entry = tk.Entry(root)
rate_entry.pack()

time_label = tk.Label(root, text="Time (years):")
time_label.pack()

time_entry = tk.Entry(root)
time_entry.pack()

calculate_button = tk.Button(root, text="Calculate Interest", command=calculate_simple_interest)
calculate_button.pack()

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

# Run the Tkinter event loop
root.mainloop()
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz