-
Notifications
You must be signed in to change notification settings - Fork 345
/
currency.py
139 lines (110 loc) · 3.87 KB
/
currency.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
root = Tk()
root.title('Codemy.com - Currency Conversion')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("500x500")
# Create Tabs
my_notebook = ttk.Notebook(root)
my_notebook.pack(pady=5)
# Create Two Frames
currency_frame = Frame(my_notebook, width=480, height=480)
conversion_frame = Frame(my_notebook, width=480, height=480)
currency_frame.pack(fill="both", expand=1)
conversion_frame.pack(fill="both", expand=1)
# Add our Tabs
my_notebook.add(currency_frame, text="Currencies")
my_notebook.add(conversion_frame, text="Convert")
# Disable 2nd tab
my_notebook.tab(1, state='disabled')
#######################
# CURRENCY STUFF
#######################
def lock():
if not home_entry.get() or not conversion_entry.get() or not rate_entry.get():
messagebox.showwarning("WARNING!", "You Didn't Fill Out All The Fields")
else:
# Disable entry boxes
home_entry.config(state="disabled")
conversion_entry.config(state="disabled")
rate_entry.config(state="disabled")
# Enable tab
my_notebook.tab(1, state='normal')
# Change Tab Field
amount_label.config(text=f'Amount of {home_entry.get()} To Convert To {conversion_entry.get()}')
converted_label.config(text=f'Equals This Many {conversion_entry.get()}')
convert_button.config(text=f'Convert From {home_entry.get()}')
def unlock():
# Enable entry boxes
home_entry.config(state="normal")
conversion_entry.config(state="normal")
rate_entry.config(state="normal")
# Disable Tab
my_notebook.tab(1, state='disabled')
home = LabelFrame(currency_frame, text="Your Home Currency")
home.pack(pady=20)
# Home currency entry box
home_entry = Entry(home, font=("Helvetica", 24))
home_entry.pack(pady=10, padx=10)
# Conversion Currency Frame
conversion = LabelFrame(currency_frame, text="Conversion Currency")
conversion.pack(pady=20)
# convert to label
conversion_label = Label(conversion, text="Currency To Convert To...")
conversion_label.pack(pady=10)
# Convert To Entry
conversion_entry = Entry(conversion, font=("Helvetica", 24))
conversion_entry.pack(pady=10, padx=10)
# rate label
rate_label = Label(conversion, text="Current Conversion Rate...")
rate_label.pack(pady=10)
# Rate To Entry
rate_entry = Entry(conversion, font=("Helvetica", 24))
rate_entry.pack(pady=10, padx=10)
# Button Frame
button_frame = Frame(currency_frame)
button_frame.pack(pady=20)
# Create Buttons
lock_button = Button(button_frame, text="Lock", command=lock)
lock_button.grid(row=0, column=0, padx=10)
unlock_button = Button(button_frame, text="Unlock", command=unlock)
unlock_button.grid(row=0, column=1, padx=10)
#######################
# CONVERSION STUFF
#######################
def convert():
# Clear Converted Entry Box
converted_entry.delete(0, END)
# Convert
conversion = float(rate_entry.get()) * float(amount_entry.get())
# Convert to two decimals
conversion = round(conversion,2)
# Add commas
conversion = '{:,}'.format(conversion)
# Upodate entry box
converted_entry.insert(0, f'${conversion}')
def clear():
amount_entry.delete(0, END)
converted_entry.delete(0, END)
amount_label = LabelFrame(conversion_frame, text="Amount To Conver")
amount_label.pack(pady=20)
# Entry Box For Amount
amount_entry = Entry(amount_label, font=("Helvetica", 24))
amount_entry.pack(pady=10, padx=10)
# Convert Button
convert_button = Button(amount_label, text="Convert", command=convert)
convert_button.pack(pady=20)
# Equals Frame
converted_label = LabelFrame(conversion_frame, text="Converted Currency")
converted_label.pack(pady=20)
# Converted entry
converted_entry = Entry(converted_label, font=("Helvetica", 24), bd=0, bg="systembuttonface")
converted_entry.pack(pady=10, padx=10)
# Clear Button
clear_button = Button(conversion_frame, text="Clear", command=clear)
clear_button.pack(pady=20)
# Fake Label for spacing
spacer = Label(conversion_frame, text="", width=68)
spacer.pack()
root.mainloop()