In this article, I am going to explain the Python tkinter simple interest program. Python Tkinter is a library which allows the creation GUI applications in python. In this article, you are going to learn the step-by-step guide for how to write Python Tkinter simple interest program. Let us begin!

Python tkinter simple interest program

The steps to do Python Tkinter simple interest program:

  1. Import python Tkinter module
  2. Design Tkinter window
  3. Add widgets to the main window
  4. Write code for buttons

So let us discuss which widgets are required to create Python tkinter simple interest program.

Widgets required for Python tkinter simple interest program

S.NoTkinter Widget
1We need 3 labels to display the appropriate messages on the screen for Principle Amount, Rate of Interest and duration.
2We need 4 entry fields out of them, 3 are required for accept data such as principle amount, rate of interest and the duration, 1 is required to show the answer
3We need 3 buttons: Compute Interest, Clear All or Reset and Exit

Here I have written a program Python tkinter simple interest program. This program has 4 entry fields, 4 labels and 3 buttons. The variables I have used for them are as following:

  1. L1 – Label for Principle Amount
  2. L2 – Label for Rate of interest
  3. L3 – Label for Duration in number of years
  4. T1 – entry field to accept principle amount
  5. T2 – entry field to accept rate of interest
  6. T3 – entry field to accept duration
  7. L4 – Label for Simple Interest text display to show interest
  8. T4 – entry field to display result
  9. B1 – Button to compute the simple interest
  10. B2 – Button to reset all entry fieds
  11. B3 – Button the close the window

User-defined functions used in the Python tkinter simple interest program

In Python tkinter simple interest program I have created three functions for three buttons.

  1. cal_si() – To accept input and calculate the simple interest. In this method, I have used the get() method to take input from the user. The set() method is used to display results in the entry field t4.
  2. clearEntry() – To clear all the text of entry fields. To clear the entries in the entry field delete() function is used and then set the focus in the back for new entry to t1, I have used focus_set() function.
  3. Me_Exit() – To close the main window I have used destroy() method inside user-defined function named Me_Exit().

Let’s start Python Tkinter simple interest program now.

Code for Python tkinter simple interest program

from tkinter import *

def cal_si():
  si=(int(t1.get())*int(t2.get())*int(t3.get()))/100
  s.set(si)

def clearEntry():
  t1.delete(0,END)
  t2.delete(0,END)
  t3.delete(0,END)
  s.set(0)
  t1.focus_set()

def Me_Exit():
  main.destroy()
  
main=Tk()
main.title('Tkinter Simple interest calculator')

main.minsize(100,100)
main.geometry('540x180')
main.resizable(False,False)

ph=PhotoImage(file='tk.png')
main.iconphoto(False,ph)

main.configure(bg="#2299AA")


s=StringVar()


l1 = Label(main, bg="#99FF99",  text="Principal Amount:",font=('Arial',16)).grid(row=1)
l2 = Label(main, bg="#99ff99", text="Rate of Interest:",font=('Arial',16)).grid(row=2)
l3 = Label(main, bg="#99FF99", text="Duration (Years):",font=('Arial',16)).grid(row=3)

  
t1 = Entry(main,font=('Arial',16))
t1.grid(row=1, column=1)
t1.focus_set()
t2 = Entry(main,font=('Arial',16))
t2.grid(row=2, column=1)
t3 = Entry(main,font=('Arial',16))
t3.grid(row=3, column=1)

b1=Button(main,text="Compute SI", command=cal_si, font=('Arial',16)).grid(row=4,column=0)
b2=Button(main,text="Clear", command=clearEntry, font=('Arial',16)).grid(row=4,column=1)
b3=Button(main,text="Exit", command=Me_Exit, font=('Arial',16)).grid(row=4,column=2)

l4 = Label(main, text="Simple Interest:",font=('Arial',16)).grid(row=5)
t4 = Entry(main, state="disabled", textvariable=s, font=('Arial',16)).grid(row=5, column=1)

Design for Python tkinter simple interest program

The output or design for Python tkinter simple interest program is as follows:

Initial Design:

Python tkinter simple interest program

Final Output:

Python tkinter simple interest program - FInal Output

Click on the respective button to give the command to this program. I have used the following websites for reference to develop this program.

  1. Python Docs
  2. Geeksforgeeks

That’s all from the Python tkinter simple interest program. I hope this program helps you to learn how to develop a Python Tkinter simple interest program. If you have any doubts or queries about this code feel free to ask in the comment section.

Kindly share your views/suggestions/feedback in the comment section for this article and hit the like button if you enjoyed learning Tkinter program here.

Thank you for reading this article.

Leave a Reply