-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkinter-demo.py
More file actions
46 lines (35 loc) · 1.75 KB
/
tkinter-demo.py
File metadata and controls
46 lines (35 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Some assignment involving TKinter. This serves as a reference
# for Python GUI during my the completion of my assigmnets.
#
# Assignment:
# Here, I import all class, function, and contsant definitions from tkinter library
from tkinter import *
# * is the wild card!
class InvestmentValueCalculator():
def __init__(self):
self.window = Tk()
self.window.title = "Investment Calculator"
#create widgets
Label(self.window, text="Investment Amont").grid(row=1, column=1, sticky= W)
Label(self.window, text="Years").grid(row=2, column=1, sticky= W)
Label(self.window, text="Annual Interest Rate").grid(row=3, column=1, sticky= W)
Label(self.window, text="Future Value").grid(row=4, column=1, sticky= W)
#member variables
self.InvestmentAmount = StringVar()
self.Years = StringVar()
self.AnnualInterestRate = StringVar()
self.FutureValue = StringVar()
#create entries
Entry(self.window, textvariable= self.InvestmentAmount, justify=RIGHT).grid(row=1, column=2)
Entry(self.window, textvariable= self.Years, justify=RIGHT) .grid(row=2, column=2)
Entry(self.window, textvariable= self.AnnualInterestRate, justify=RIGHT).grid(row=3, column=2)
Label(self.window, textvariable= self.FutureValue, justify=RIGHT).grid(row=4, column=2)
#create button
self.button = Button(self.window, text="Calculate", command=self.onClick).grid(row=5,column=1)
#start loop
self.window.mainloop()
def onClick(self):
self.FutureValue.set(str( \
float(self.InvestmentAmount) * (1 + float(self.AnnualInterestRate)/12 )**(float(self.Years) * 12.0)
))
program = InvestmentValueCalculator()