Python – Compound Interest GUI Calculator using Tkinter

Last Updated : 08 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisites : Introduction to tkinter | Program to calculate compound interest

Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. In this article, we will learn how to create a Compound Interest GUI Calculator application using Tkinter, with a step-by-step guide.
 

To create a Tkinter: 

  • Importing the module – tkinter
  • Create the main window (container)
  • Add any number of widgets to the main window.
  • Apply the event Trigger on the widgets.

Below is what the GUI will look like:

Let’s create a GUI based Compound Interest Calculator application.
 

Below is the implementation :
 

Python3




# import all classes / functions from the tkinter
from tkinter import *
 
# Function for clearing the 
# contents of all entry boxes  
def clear_all() :
 
    # whole content of entry boxes is deleted
    principal_field.delete(0, END)  
    rate_field.delete(0, END)
    time_field.delete(0, END)
    compound_field.delete(0, END)
   
    # set focus on the principal_field entry box 
    principal_field.focus_set()
 
 
# Function to find compound interest 
def calculate_ci():
 
    # get a content from entry box
    principal = int(principal_field.get())
     
    rate = float(rate_field.get())
 
    time = int(time_field.get())
     
    # Calculates compound interest 
    CI = principal * (pow((1 + rate / 100), time))
 
    # insert method inserting the 
    # value in the text entry box.
    compound_field.insert(10, CI)
 
     
 
# Driver code
if __name__ == "__main__" :
   
    # Create a GUI window
    root = Tk()
   
    # Set the background colour of GUI window
    root.configure(background = 'light green')
   
    # Set the configuration of GUI window
    root.geometry("400x250")
   
    # set the name of tkinter GUI window
    root.title("Compound Interest Calculator"
       
    # Create a Principal Amount : label
    label1 = Label(root, text = "Principal Amount(Rs) : ",
                   fg = 'black', bg = 'red')
   
    # Create a Rate : label
    label2 = Label(root, text = "Rate(%) : ",
                   fg = 'black', bg = 'red')
       
    # Create a Time : label
    label3 = Label(root, text = "Time(years) : ",
                   fg = 'black', bg = 'red')
 
    # Create a Compound Interest : label
    label4 = Label(root, text = "Compound Interest : ",
                   fg = 'black', bg = 'red')
 
    # grid method is used for placing 
    # the widgets at respective positions 
    # in table like structure .
 
    # padx keyword argument used to set padding along x-axis .
    # pady keyword argument used to set padding along y-axis .
    label1.grid(row = 1, column = 0, padx = 10, pady = 10
    label2.grid(row = 2, column = 0, padx = 10, pady = 10
    label3.grid(row = 3, column = 0, padx = 10, pady = 10)
    label4.grid(row = 5, column = 0, padx = 10, pady = 10)
 
    # Create a entry box 
    # for filling or typing the information.
    principal_field = Entry(root) 
    rate_field = Entry(root) 
    time_field = Entry(root)
    compound_field = Entry(root)
 
    # grid method is used for placing 
    # the widgets at respective positions 
    # in table like structure .
     
    # padx keyword argument used to set padding along x-axis .
    # pady keyword argument used to set padding along y-axis .
    principal_field.grid(row = 1, column = 1, padx = 10, pady = 10
    rate_field.grid(row = 2, column = 1, padx = 10, pady = 10
    time_field.grid(row = 3, column = 1, padx = 10, pady = 10)
    compound_field.grid(row = 5, column = 1, padx = 10, pady = 10)
 
    # Create a Submit Button and attached 
    # to calculate_ci function 
    button1 = Button(root, text = "Submit", bg = "red"
                     fg = "black", command = calculate_ci)
   
    # Create a Clear Button and attached 
    # to clear_all function 
    button2 = Button(root, text = "Clear", bg = "red"
                     fg = "black", command = clear_all)
   
    button1.grid(row = 4, column = 1, pady = 10)
    button2.grid(row = 6, column = 1, pady = 10)
 
    # Start the GUI 
    root.mainloop()
    


Output : 
 



Previous Article
Next Article

Similar Reads

Python | Simple GUI calculator using Tkinter
Prerequisite: Tkinter Introduction, lambda function Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI a
6 min read
Python | Distance-time GUI calculator using Tkinter
Prerequisites : Introduction to Tkinter | Using google distance matrix API Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest wa
7 min read
Python - Dynamic GUI Calculator using Tkinter module
Python provides many options for developing GUI like Kivy, PyQT, WxPython, and several others. Tkinter is the one that is shipped inbuilt with python which makes it the most commonly used out of all. Tkinter is easy, fast, and powerful. Beginners can easily learn to create a simple calculator using this article: Python | Simple GUI calculator using
3 min read
Scientific GUI Calculator using Tkinter in Python
Prerequisite: Python GUI – tkinter In this article, we are going to create GUI Scientific Calculator using Python. As you can see, calculating large numbers nowadays is difficult or time-consuming. We've created a simple Scientific Calculator GUI using Python that allows you to perform simple and complex calculations. To implement GUI we will use t
13 min read
Rank Based Percentile Gui Calculator using Tkinter
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. In this article, we will learn how to create a Rank Based - Percentile Gui Calculator application using Tkinter, with a step-by-step guide. Prerequisites: Introduction to TkinterProgram to calculate t
7 min read
Ratio Calculator GUI using Tkinter
Prerequisite: Python GUI – tkinter Tkinter is the most commonly used library for developing GUI (Graphical User Interface) in Python. It is a standard Python interface to the Tk GUI toolkit shipped with Python. As Tk and Tkinter are available on most of the Unix platforms as well as on the Windows system, developing GUI applications with Tkinter be
3 min read
Python | Create a GUI Marksheet using Tkinter
Create a python GUI mark sheet. Where credits of each subject are given, enter the grades obtained in each subject and click on Submit. The credits per subject, the total credits as well as the SGPA are displayed after being calculated automatically. Use Tkinter to create the GUI interface. Refer the below articles to get the idea about basics of t
8 min read
Python: Weight Conversion GUI using Tkinter
Prerequisites: Python GUI – tkinterPython offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI applications. Crea
2 min read
Python | ToDo GUI Application using Tkinter
Prerequisites : Introduction to tkinter Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. In this article, we will learn how to create a ToDo GUI application using Tkinter, with a step-by-step guide. To create a tkinter : Importing the module – tkinter
5 min read
Python | GUI Calendar using Tkinter
Prerequisites: Introduction to Tkinter Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications. In this article, we will learn how to create a GUI Calendar application using
4 min read
three90RightbarBannerImg