1+ # import all classes / functions from the tkinter 
2+ from  tkinter  import  * 
3+ 
4+ # Function for clearing the  
5+ # contents of all entry boxes  
6+ def  clear_all () :
7+ 
8+ 	# whole content of entry boxes is deleted  
9+ 	principal_field .delete (0 , END ) 
10+ 	rate_field .delete (0 , END ) 
11+ 	time_field .delete (0 , END )
12+ 	compound_field .delete (0 , END )
13+ 
14+ 	# set focus on the principal_field entry box  
15+ 	principal_field .focus_set () 
16+ 
17+ 
18+ # Function to find compound interest  
19+ def  calculate_ci (): 
20+ 
21+ 	# get a content from entry box 
22+ 	principal  =  int (principal_field .get ())
23+ 	
24+ 	rate  =  float (rate_field .get ())
25+ 
26+ 	time  =  int (time_field .get ())
27+ 	
28+ 	# Calculates compound interest  
29+ 	CI  =  principal  *  (pow ((1  +  rate  /  100 ), time ))
30+ 
31+ 	# insert method inserting the  
32+ 	# value in the text entry box. 
33+ 	compound_field .insert (10 , CI )
34+ 
35+ 	
36+ 
37+ # Driver code  
38+ if  __name__  ==  "__main__"  : 
39+ 
40+ 	# Create a GUI window  
41+ 	root  =  Tk () 
42+ 
43+ 	# Set the background colour of GUI window  
44+ 	root .configure (background  =  'dark blue' ) 
45+ 
46+ 	# Set the configuration of GUI window  
47+ 	root .geometry ("400x250" ) 
48+ 
49+ 	# set the name of tkinter GUI window  
50+ 	root .title ("Compound Interest Calculator" ) 
51+ 	
52+ 	# Create a Principal Amount : label  
53+ 	label1  =  Label (root , text  =  "Principal Amount(Rs) : " , 
54+ 				fg  =  'white' , bg  =  'red' ) 
55+ 
56+ 	# Create a Rate : label  
57+ 	label2  =  Label (root , text  =  "Rate(%) : " , 
58+ 				fg  =  'white' , bg  =  'red' ) 
59+ 	
60+ 	# Create a Time : label  
61+ 	label3  =  Label (root , text  =  "Time(years) : " , 
62+ 				fg  =  'white' , bg  =  'red' )
63+ 
64+ 	# Create a Compound Interest : label  
65+ 	label4  =  Label (root , text  =  "Compound Interest : " , 
66+ 				fg  =  'white' , bg  =  'red' ) 
67+ 
68+ 	# grid method is used for placing  
69+ 	# the widgets at respective positions  
70+ 	# in table like structure . 
71+ 
72+ 	# padx keyword argument used to set padding along x-axis . 
73+ 	# pady keyword argument used to set padding along y-axis .  
74+ 	label1 .grid (row  =  1 , column  =  0 , padx  =  10 , pady  =  10 ) 
75+ 	label2 .grid (row  =  2 , column  =  0 , padx  =  10 , pady  =  10 ) 
76+ 	label3 .grid (row  =  3 , column  =  0 , padx  =  10 , pady  =  10 )
77+ 	label4 .grid (row  =  5 , column  =  0 , padx  =  10 , pady  =  10 )
78+ 
79+ 	# Create a entry box  
80+ 	# for filling or typing the information. 
81+ 	principal_field  =  Entry (root ) 
82+ 	rate_field  =  Entry (root ) 
83+ 	time_field  =  Entry (root )
84+ 	compound_field  =  Entry (root )
85+ 
86+ 	# grid method is used for placing  
87+ 	# the widgets at respective positions  
88+ 	# in table like structure . 
89+ 	
90+ 	# padx keyword argument used to set padding along x-axis . 
91+ 	# pady keyword argument used to set padding along y-axis .  
92+ 	principal_field .grid (row  =  1 , column  =  1 , padx  =  10 , pady  =  10 ) 
93+ 	rate_field .grid (row  =  2 , column  =  1 , padx  =  10 , pady  =  10 ) 
94+ 	time_field .grid (row  =  3 , column  =  1 , padx  =  10 , pady  =  10 )
95+ 	compound_field .grid (row  =  5 , column  =  1 , padx  =  10 , pady  =  10 )
96+ 
97+ 	# Create a Submit Button and attached  
98+ 	# to calculate_ci function  
99+ 	button1  =  Button (root , text  =  "Submit" , bg  =  "red" , 
100+ 					fg  =  "black" , command  =  calculate_ci ) 
101+ 
102+ 	# Create a Clear Button and attached  
103+ 	# to clear_all function  
104+ 	button2  =  Button (root , text  =  "Clear" , bg  =  "red" , 
105+ 					fg  =  "black" , command  =  clear_all )
106+ 
107+ 	button1 .grid (row  =  4 , column  =  1 , pady  =  10 ) 
108+ 	button2 .grid (row  =  6 , column  =  1 , pady  =  10 )
109+ 
110+ 	# Start the GUI  
111+ 	root .mainloop ()
112+ 	
0 commit comments