Create a GUI to input Principal amount, rate of interest and number of
years, Calculate Compound interest. When button submit is pressed
Compound interest should be displayed in a textbox. When clear button is
pressed all contents should be cleared.
Source code:
from tkinter import *
def clear_all() :
p_field.delete(0, END)
r_field.delete(0, END)
t_field.delete(0, END)
compound_field.delete(0, END)
p_field.focus_set()
def calculate_ci():
p = int(p_field.get())
r = float(r_field.get())
t = int(t_field.get())
CI = p * (pow((1 + r / 100), t))-p
compound_field.insert(0,CI)
if __name__ == "__main__" :
root = Tk()
[Link](background = 'light blue')
[Link]("400x250")
[Link]("Compound Interest Calculator")
label1 = Label(root, text = "Principle Amount(Rs) : ", fg = 'black',bg ='red')
label2 = Label(root, text = "Rate(%) : ",fg = 'black', bg = 'red')
label3 = Label(root, text = "Time(years) : ", fg = 'black', bg = 'red')
label4 = Label(root, text = "Compound Interest : ", fg = 'black', bg = 'red')
[Link](row = 1, column = 0, padx = 10, pady = 10)
[Link](row = 2, column = 0, padx = 10, pady = 10)
[Link](row = 3, column = 0, padx = 10, pady = 10)
[Link](row = 5, column = 0, padx = 10, pady = 10)
p_field = Entry(root)
r_field = Entry(root)
t_field = Entry(root)
compound_field = Entry(root)
p_field.grid(row = 1, column = 1, padx = 10, pady = 10)
r_field.grid(row = 2, column = 1, padx = 10, pady = 10)
t_field.grid(row = 3, column = 1, padx = 10, pady = 10)
compound_field.grid(row = 5, column = 1, padx = 10, pady = 10)
button1 = Button(root, text = "Submit", bg = "red", fg = "black", command
= calculate_ci)
button2 = Button(root, text = "Clear", bg = "red", fg = "black", command
= clear_all)
[Link](row = 4, column = 1, pady = 10)
[Link](row = 6, column = 1, pady = 10)
[Link]()
Output: