-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinterest-tk.pyw
More file actions
executable file
·99 lines (84 loc) · 3.94 KB
/
interest-tk.pyw
File metadata and controls
executable file
·99 lines (84 loc) · 3.94 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# Copyright (c) 2008-11 Qtrac Ltd. All rights reserved.
# This program or module is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. It is provided for educational
# purposes and is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
import os
import sys
import tkinter
class MainWindow(tkinter.Frame):
def __init__(self, parent):
super().__init__(parent)
self.parent = parent
self.grid(row=0, column=0)
self.principal = tkinter.DoubleVar()
self.principal.set(1000.0)
self.rate = tkinter.DoubleVar()
self.rate.set(5.0)
self.years = tkinter.IntVar()
self.amount = tkinter.StringVar()
principalLabel = tkinter.Label(self, text="Principal $:",
anchor=tkinter.W, underline=0)
principalScale = tkinter.Scale(self, variable=self.principal,
command=self.updateUi, from_=100, to=10000000,
resolution=100, orient=tkinter.HORIZONTAL)
rateLabel = tkinter.Label(self, text="Rate %:", underline=0,
anchor=tkinter.W)
rateScale = tkinter.Scale(self, variable=self.rate,
command=self.updateUi, from_=1, to=100,
resolution=0.25, digits=5, orient=tkinter.HORIZONTAL)
yearsLabel = tkinter.Label(self, text="Years:", underline=0,
anchor=tkinter.W)
yearsScale = tkinter.Scale(self, variable=self.years,
command=self.updateUi, from_=1, to=50,
orient=tkinter.HORIZONTAL)
amountLabel = tkinter.Label(self, text="Amount $",
anchor=tkinter.W)
actualAmountLabel = tkinter.Label(self,
textvariable=self.amount, relief=tkinter.SUNKEN,
anchor=tkinter.E)
principalLabel.grid(row=0, column=0, padx=2, pady=2,
sticky=tkinter.W)
principalScale.grid(row=0, column=1, padx=2, pady=2,
sticky=tkinter.EW)
rateLabel.grid(row=1, column=0, padx=2, pady=2,
sticky=tkinter.W)
rateScale.grid(row=1, column=1, padx=2, pady=2,
sticky=tkinter.EW)
yearsLabel.grid(row=2, column=0, padx=2, pady=2,
sticky=tkinter.W)
yearsScale.grid(row=2, column=1, padx=2, pady=2,
sticky=tkinter.EW)
amountLabel.grid(row=3, column=0, padx=2, pady=2,
sticky=tkinter.W)
actualAmountLabel.grid(row=3, column=1, padx=2, pady=2,
sticky=tkinter.EW)
principalScale.focus_set()
self.updateUi()
parent.bind("<Alt-p>", lambda *ignore: principalScale.focus_set())
parent.bind("<Alt-r>", lambda *ignore: rateScale.focus_set())
parent.bind("<Alt-y>", lambda *ignore: yearsScale.focus_set())
parent.bind("<Control-q>", self.quit)
parent.bind("<Escape>", self.quit)
def updateUi(self, *ignore):
amount = self.principal.get() * (
(1 + (self.rate.get() / 100.0)) ** self.years.get())
self.amount.set("{0:.2f}".format(amount))
def quit(self, event=None):
self.parent.destroy()
application = tkinter.Tk()
path = os.path.join(os.path.dirname(__file__), "images/")
if sys.platform.startswith("win"):
icon = path + "interest.ico"
else:
icon = "@" + path + "interest.xbm"
application.iconbitmap(icon)
application.title("Interest")
window = MainWindow(application)
application.protocol("WM_DELETE_WINDOW", window.quit)
application.mainloop()