Python Project – Compound Interest Calculator

FREE Online Courses: Transform Your Career – Enroll for Free!

This project is a simple compound interest calculator implemented using the Tkinter library in Python. Tkinter is a standard GUI (Graphical User Interface) toolkit for creating desktop applications. The calculator allows users to input the principal amount, annual interest rate, time, and compounding frequency. The compounding interest formula is then applied to calculate the future value of the investment.

The GUI is designed with a blue background and various input fields and labels. Users can click the “Calculate” button to perform the calculation, and the result is displayed in a labeled area. The color scheme uses dark pink, green, and white for a visually appealing interface. The project provides a basic example of creating a GUI-based financial calculator using Tkinter in Python.

About Python Compound Interest Calculator Project

The “Compound Interest Calculator” is a simple financial tool designed using Tkinter, a Python GUI library. This project provides users with a user-friendly interface to calculate compound interest based on their input values. Users can input the principal amount, annual interest rate, and time period in years and choose the compounding frequency (annually, semi-annually, quarterly, or monthly) from a convenient dropdown menu.

The calculation is performed using the compound interest formula, and the future value is displayed on the GUI. The application is not only functional but also visually appealing, with color-coded labels, entry fields, and buttons. Users can easily interact with the calculator to make informed financial decisions related to compound interest. The project demonstrates the integration of financial formulas with a graphical user interface, making it accessible for users to compute compound interest effortlessly.

Prerequisites For Python Compound Interest Calculator Project

1. Python and Tkinter Installation:

Tkinter is a standard Python library for GUI development and usually comes bundled with Python. Verify its presence, or install it using `pip install tk`.

2. Code Editor or IDE:

Choose a code editor or integrated development environment (IDE) to run the Tkinter script. Examples include Visual Studio Code, PyCharm, or IDLE.

Download Python Compound Interest Calculator Project

Please download the source code of the Python Compound Interest Calculator Project: Python Compound Interest Calculator Project Code.

File Structure of Python Compound Interest Calculator Project

The Python script creates a compound interest calculator GUI using Tkinter with the following structure:

1. User Interface Setup:

Defines a Tkinter window with labels, entry fields, a combo box, a calculate button, and a result label for user input and output.

2. Input Handling:

Retrieves user inputs for principal, rate, time, and compounding frequency and sets default values for the compounding frequency combo box.

3. Calculation Function:

Implements a `calculate_interest` function to perform compound interest calculations based on user inputs and updates the result label with the computed future value.

 4. Visual Styling:

Applies a specific color scheme using Tkinter styles to enhance the visual appeal of the GUI components, including labels, entry fields, and the calculate button.

Compound Interest Formula

FV = P * (1 + (R/n)) ^ (n*t)

Where:

FV – is the Future Value (calculated by the code and displayed as the result).
P is the Principal Amount (input by the user through the GUI entry field).
R is the Annual Interest Rate (input by the user through the GUI entry field, converted to a decimal in the code).
n is the Compounding Frequency, i.e., the number of compounding periods per year (input by the user through the GUI combobox).
t is the Time Period in years (input by the user through the GUI entry field)

Implementation of Python Compound Interest Calculator Project

1. Importing Libraries:

The code begins by importing the required libraries: `tkinter` for GUI components and `ttk` for themed Tkinter widgets.

import tkinter as tk
from tkinter import ttk

2. Function for Compound Interest Calculation:

Next, a function `calculate_interest()` is defined. This function retrieves input values (principal, rate, time, and compounding frequency) from the GUI, performs the compound interest calculation, and updates the result label.

def calculate_interest():
   principal = float(principal_entry.get())
   rate = float(rate_entry.get()) / 100
   time = float(time_entry.get())
   compounding_frequency = int(compounding_frequency_combobox.get())


   # Compound Interest Formula
   future_value = principal * (1 + rate / compounding_frequency) ** (compounding_frequency * time)


   result_label.config(text=f"Future Value: ₹{future_value:.2f}")

3. Creating the Main Window:

The main Tkinter window is created with a specified title, dimensions, and background color.

# Create the main window
root = tk.Tk()
root.title("Flood-Compound Interest Calculator")
root.geometry("400x300")


# Set background color to blue
root.configure(bg='#3498db')

Tk() – class is created, representing the main window
title() – sets the window title
geometry() – sets the window size (width x height)
configure() – is used to set the background color

4. Creating and Placing Widgets:

Labels, entry fields, combo box, button, and result label widgets are created using `ttk` widgets. They are placed in the window using the `grid` layout manager.

principal_label = ttk.Label(root, text="Principal Amount:", foreground='#FF1493')
principal_entry = ttk.Entry(root)


rate_label = ttk.Label(root, text="Annual Interest Rate (%):", foreground='#FF1493')
rate_entry = ttk.Entry(root)


time_label = ttk.Label(root, text="Time Period (years):", foreground='#FF1493')
time_entry = ttk.Entry(root)


compounding_frequency_label = ttk.Label(root, text="Compounding Frequency:", foreground='#FF1493')
compounding_frequency_combobox = ttk.Combobox(root, values=["1", "2", "4", "12"])


calculate_button = ttk.Button(root, text="Calculate", command=calculate_interest, style='Green.TButton')
result_label = ttk.Label(root, text="Future Value: ₹0.00", foreground='#FF1493')

5. Styling the Calculate Button:

A style is configured for the Calculate button to change its appearance (foreground and background color).

# Create a style for the Calculate button
style = ttk.Style()
style.configure('Green.TButton', foreground='#FFFFFF', background='#4CAF50')

6. Placing Widgets in the Grid Layout:

The widgets are placed in the grid layout using the `grid` method, specifying row and column positions.

principal_label.grid(row=0, column=0, padx=10, pady=10)
principal_entry.grid(row=0, column=1, padx=10, pady=10)


rate_label.grid(row=1, column=0, padx=10, pady=10)
rate_entry.grid(row=1, column=1, padx=10, pady=10)


time_label.grid(row=2, column=0, padx=10, pady=10)
time_entry.grid(row=2, column=1, padx=10, pady=10)


compounding_frequency_label.grid(row=3, column=0, padx=10, pady=10)
compounding_frequency_combobox.grid(row=3, column=1, padx=10, pady=10)


calculate_button.grid(row=4, column=0, columnspan=2, pady=10)
result_label.grid(row=5, column=0, columnspan=2, pady=10)

-The grid() – method is used to place the widgets in a grid layout within the main window.
-The row and column parameters determine the position, and padx and pady add padding around each widget.

7. Running the Main Loop:

Finally, the main loop is started to display the GUI and handle user interactions.

# Run the main loop
root.mainloop()

Python Code

import tkinter as tk
from tkinter import ttk


def calculate_interest():
   principal = float(principal_entry.get())
   rate = float(rate_entry.get()) / 100
   time = float(time_entry.get())
   compounding_frequency = int(compounding_frequency_combobox.get())


   # Compound Interest Formula
   future_value = principal * (1 + rate / compounding_frequency) ** (compounding_frequency * time)


   result_label.config(text=f"Future Value: ₹{future_value:.2f}")


# Create the main window
root = tk.Tk()
root.title("Flood-Compound Interest Calculator")
root.geometry("400x300")


# Set background color to blue
root.configure(bg='#3498db')


# Create and place widgets
principal_label = ttk.Label(root, text="Principal Amount:", foreground='#FF1493')  # Dark Pink color
principal_label.grid(row=0, column=0, padx=10, pady=10)


principal_entry = ttk.Entry(root)
principal_entry.grid(row=0, column=1, padx=10, pady=10)


rate_label = ttk.Label(root, text="Annual Interest Rate (%):", foreground='#FF1493')  # Dark Pink color
rate_label.grid(row=1, column=0, padx=10, pady=10)


rate_entry = ttk.Entry(root)
rate_entry.grid(row=1, column=1, padx=10, pady=10)


time_label = ttk.Label(root, text="Time Period (years):", foreground='#FF1493')  # Dark Pink color
time_label.grid(row=2, column=0, padx=10, pady=10)


time_entry = ttk.Entry(root)
time_entry.grid(row=2, column=1, padx=10, pady=10)


compounding_frequency_label = ttk.Label(root, text="Compounding Frequency:", foreground='#FF1493')  # Dark Pink color
compounding_frequency_label.grid(row=3, column=0, padx=10, pady=10)


compounding_frequency_combobox = ttk.Combobox(root, values=["1", "2", "4", "12"])
compounding_frequency_combobox.set("1")
compounding_frequency_combobox.grid(row=3, column=1, padx=10, pady=10)


# Create a style for the Calculate button
style = ttk.Style()
style.configure('Green.TButton', foreground='#FFFFFF', background='#4CAF50')


calculate_button = ttk.Button(root, text="Calculate", command=calculate_interest, style='Red.TButton')  # Green color
calculate_button.grid(row=4, column=0, columnspan=2, pady=10)


result_label = ttk.Label(root, text="Future Value: ₹0.00", foreground='#FF1493')  # White color
result_label.grid(row=5, column=0, columnspan=2, pady=10)


# Run the main loop
root.mainloop()

Python Compound Interest Calculator Output

 

 

python compound interest calculator project output

python compound interest calculator output

Conclusion

This project implements a simple yet effective compound interest calculator using the Tkinter library in Python. The graphical user interface (GUI) allows users to input the principal amount, annual interest rate, time period, and compounding frequency. The compound interest formula is applied to calculate the future value of the investment or loan, and the result is displayed on the GUI.

The design is visually appealing, with labels, entry fields, a combobox, and a button laid out in a user-friendly grid format. The color styling adds a touch of elegance to the interface, making it more engaging for users. Additionally, the code exhibits good practices by incorporating a function for interest calculation, promoting modularity and maintainability.

Overall, this project serves as an excellent example of combining Python’s Tkinter for GUI development with fundamental financial calculations to create a practical and user-friendly compound interest calculator.

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google | Facebook


Leave a Reply

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