-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTuition.py
59 lines (42 loc) · 1.85 KB
/
Tuition.py
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
from tkinter import *
# Getting the GUI going.
root = Tk()
root.title("Tuition Calculator")
root.configure(background='black')
root.geometry("395x175")
# Defining the initial label that shows when program starts.
tuitionOutput = Label(root, text="Press Calculate or Alt-c to calculate tuition\n "
"Press Exit or Alt-e to kill the program\n\n\n",
bg="black", fg="cyan", font="Helvetica 12", wraplength=400)
tuitionOutput.pack(padx=5, pady=5)
# Making the calculate button.
calculateButton = Button(root, text="Calculate", bg="seashell3", highlightbackground="black",
fg="blue", font="Helvetica 7 bold")
calculateButton.pack(padx=5, pady=5)
# This is for the Exit button.
exitButton = Button(root, text="Exit", command=root.destroy, bg="seashell3", highlightbackground="black", fg="blue",
font="Helvetica 7 bold")
exitButton.pack(padx=5, pady=5)
# Here we do the tuition calculation in a for loop.
def calculate_tuition():
tuition = 8000
increase = .03
for year in range(1, 6):
# Adding accumulator here
tuition += tuition * increase
# Logic to not grab the welcome text and only append the tuition output.
if year == 1:
tuitionOutput.configure(text="The tuition for year " + f"{year} " + f"is: ${tuition:.2f}\n")
else:
tuitionOutput.configure(text=tuitionOutput.cget("text") + "The tuition for year " + f"{year} " +
f"is: ${tuition:.2f}\n", pady=0)
calculateButton.configure(pady=0)
# Function used for key bind.
def destroy():
root.destroy()
# Key stroke bindings.
root.bind('<Alt_L><c>', lambda e: calculate_tuition())
root.bind('<Alt_L><e>', lambda f: destroy())
# Button set to calculate!
calculateButton.configure(command=calculate_tuition)
root.mainloop()