-
Notifications
You must be signed in to change notification settings - Fork 1
/
age_calc_gui.py
322 lines (264 loc) · 8.61 KB
/
age_calc_gui.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/python3
#===============MODULES===============#
import tkinter as tk
from tkinter import PhotoImage, messagebox
import datetime, os
#===============ROOT WINDOW===============#
root = tk.Tk()
root.title("Age Calculator")
root.geometry("571x590")
root.minsize(450, 590)
icon_path = os.path.expanduser('~/.local/share/icons/age_calculator_gui/age_calculator.png')
icon = PhotoImage(file = icon_path)
root.iconphoto(False, icon)
root.config(bg = "#333")
'''
_____ _ _ _ _ ____ _____ ___ ___ _ _ ____
| ___| | | | \ | |/ ___|_ _|_ _/ _ \| \ | / ___|
| |_ | | | | \| | | | | | | | | | \| \___ \
| _| | |_| | |\ | |___ | | | | |_| | |\ |___) |
|_| \___/|_| \_|\____| |_| |___\___/|_| \_|____/
'''
#===============Variables===============#
day_clicks = month_clicks = year_clicks = 0
y0 = int(datetime.date.today().strftime("%Y"))
m0 = int(datetime.date.today().strftime("%m"))
d0 = int(datetime.date.today().strftime("%d"))
#===============CLEAR FRAME===============#
def clear_out():
for widgets in frame_04.winfo_children():
widgets.destroy()
for widgets in frame_05.winfo_children():
widgets.destroy()
#===============TEXT OUTPUT===============#
def text_out():
try:
global d0, m0, y0, clicks
d0, m0, y0 = int(entry_04.get()), int(entry_05.get()), int(entry_06.get())
y1 = int(entry_03.get())
m1 = int(entry_02.get())
d1 = int(entry_01.get())
date = datetime.date(y0, m0, d0)
DOB = datetime.date(y1, m1, d1)
age_days = (date - DOB).days
age_months = age_days/30.4375
age_weeks = age_days/7
age_years = age_days/365.25
age_hours = age_days*24
age_minutes = age_hours*60
age_seconds = age_minutes*60
years = int(age_years)
months = int((age_years - years)*12)
days = int((((age_years - years)*12) - months)*30.4375)
nxt_year = (y1+years+1)
nxt_DOB = datetime.date(nxt_year, m1, d1)
rem_days = (nxt_DOB - date).days
rem_months = rem_days/30.4375
rem_weeks = rem_days/7
rem_hours = rem_days*24
rem_minutes = rem_hours*60
rem_seconds = rem_minutes*60
rem_months1 = int(rem_months)
rem_days1 = int((rem_months - int(rem_months))*30.4375)
clear_out()
#===============ERRORS===============#
if y1 <= 0 or y1 > y0 or y0 <= 0:
messagebox.showerror(
"Error",
"Please Input The Correct Year")
elif (m1 <= 0 and m0 <= 0) or (m1 == m0 and d1 >= d0 and y0 == y1):
messagebox.showerror(
"Error",
"Please Input The Correct Day")
else:
tk.Message(
frame_04,
text = "Total Years: "+str(age_years)+" Years"+"\nTotal Months: "+str(age_months)+" Months"+"\nTotal Weeks: "+str(age_weeks)+" weeks"+"\nTotal Days: "+str(age_days)+" Days\nTotal Hours: "+str(age_hours)+" Hours (Approx)\n"+"Total Minutes: "+str(age_minutes)+" Minutes (Approx)\n"+"Total Seconds: "+str(age_seconds)+" Seconds (Approx)"+"\n\nYou are "+str(years)+" Years, "+str(months)+" Months, "+str(days)+" Days old",
bg = "#333",
fg = "#fff",
width = 2000).pack(
anchor = "w")
tk.Message(
frame_05,
text = "Total Months: "+str(rem_months)+" Months\nTotal Weeks: "+str(rem_weeks)+" weeks\nTotal Days: "+str(rem_days)+" Days\nTotal Hours: "+str(rem_hours)+" Hours (Approx)\nTotal Minutes: "+str(rem_minutes)+" Minutes (Approx)\nTotal Seconds: "+str(rem_seconds)+" Seconds (Approx)"+"\n\n"+str(rem_months1)+" Months, "+str(rem_days1)+" days remainig for you next birthday",
bg = "#333",
fg = "#fff",
width = 2000).pack(
anchor = "w")
except:
clear_out()
if m1 <= 0 or m1 > 12 or m0 <= 0 or m0 > 12:
messagebox.showerror(
"Error",
"Please Input The Correct Month")
else:
messagebox.showerror(
"Error",
"An Error Occured\nPlease Check Your Input")
'''
_____ ____ _ __ __ _____ ____
| ___| _ \ / \ | \/ | ____/ ___|
| |_ | |_) | / _ \ | |\/| | _| \___ \
| _| | _ < / ___ \| | | | |___ ___) |
|_| |_| \_\/_/ \_\_| |_|_____|____/
'''
#===============FRAME 01===============#
frame_01 = tk.LabelFrame(
root,
text = "Your Age",
borderwidth = 2,
bg = "#333",
fg = "#fff")
dateFrame = tk.Frame(frame_01, bg = "#333")
#===============FRAME 02===============#
frame_02 = tk.LabelFrame(
root,
text = "Date",
borderwidth = 2,
bg = "#333",
fg = "#fff")
ageFrame = tk.Frame(frame_02, bg = "#333")
#===============FRAME 03===============#
frame_03 = tk.Frame(
root,
bg = "#333")
#===============FRAME 04===============#
frame_04 = tk.LabelFrame(
root,
text = "Your Age",
borderwidth = 5,
bg = "#333",
fg = "#fff")
frame_05 = tk.LabelFrame(
root,
text = "Next Birthday",
borderwidth = 5,
bg = "#333",
fg = "#fff")
'''
_____ _ _ _____ ____ ___ _____ ____
| ____| \ | |_ _| _ \|_ _| ____/ ___|
| _| | \| | | | | |_) || || _| \___ \
| |___| |\ | | | | _ < | || |___ ___) |
|_____|_| \_| |_| |_| \_\___|_____|____/
'''
#===============ENTRY 01===============#
def temp_text(e):
global day_clicks
if day_clicks == 0:
entry_01.delete(0,"end")
day_clicks = 1
entry_01 = tk.Entry(
dateFrame,
bg = "#444",
fg = "#fff")
entry_01.insert(0, "Day")
entry_01.bind("<FocusIn>", temp_text)
#===============ENTRY 02===============#
def temp_text(e):
global month_clicks
if month_clicks == 0:
entry_02.delete(0,"end")
month_clicks = 1
entry_02 = tk.Entry(
dateFrame,
bg = "#444",
fg = "#fff")
entry_02.insert(0, "Month")
entry_02.bind("<FocusIn>", temp_text)
#===============ENTRY 03===============#
def temp_text(e):
global year_clicks
if year_clicks == 0:
entry_03.delete(0,"end")
year_clicks = 1
entry_03 = tk.Entry(
dateFrame,
bg = "#444",
fg = "#fff")
entry_03.insert(0, "Year")
entry_03.bind("<FocusIn>", temp_text)
#===============ENTRY 04===============#
entry_04 = tk.Entry(
ageFrame,
bg = "#444",
fg = "#fff")
entry_04.insert(0, d0)
#===============ENTRY 05===============#
entry_05 = tk.Entry(
ageFrame,
bg = "#444",
fg = "#fff")
entry_05.insert(0, m0)
#===============ENTRY 06===============#
entry_06 = tk.Entry(
ageFrame,
bg = "#444",
fg = "#fff")
entry_06.insert(0, y0)
'''
____ _ _ _____ _____ ___ _ _ ____
| __ )| | | |_ _|_ _/ _ \| \ | / ___|
| _ \| | | | | | | || | | | \| \___ \
| |_) | |_| | | | | || |_| | |\ |___) |
|____/ \___/ |_| |_| \___/|_| \_|____/
'''
#===============BUTTON 01===============#
button_01 = tk.Button(
frame_03,
text = "Claculate",
bg = "#444",
fg = "#fff",
activebackground = "#555",
command = text_out)
#===============BUTTON 02===============#
button_02 = tk.Button(
frame_03,
text = "Clear All",
bg = "#444",
fg = "#fff",
activebackground = "#555",
command = clear_out)
'''
____ _ ____ _ __ _ _ _ ____ ____ ____ ___ ____
| _ \ / \ / ___| |/ / / \ | \ | | _ \ / ___| _ \|_ _| _ \
| |_) / _ \| | | ' / / _ \ | \| | | | | | | _| |_) || || | | |
| __/ ___ \ |___| . \ / ___ \| |\ | |_| | | |_| | _ < | || |_| |
|_| /_/ \_\____|_|\_\ /_/ \_\_| \_|____/ \____|_| \_\___|____/
'''
#===============FRAMES===============#
ageFrame.pack()
dateFrame.pack()
frame_02.pack(
padx = 5,
pady = 0,
fill="both")
frame_01.pack(
padx = 5,
pady = 0,
fill="both")
frame_04.pack(
pady = (5,0),
padx = 5,
fill = "both",
expand = True)
frame_05.pack(
pady = (0,5),
padx = 5,
fill = "both",
expand = True)
frame_03.pack(pady=5)
frame_04.propagate(0)
frame_05.propagate(0)
#===============ENTRIES===============#
entry_01.pack(side="left", padx=(10, 0), pady=10, fill="x")
entry_02.pack(side="left", padx=(10, 0), pady=10, fill="x")
entry_03.pack(side="left", padx=(10, 0), pady=10, fill="x")
entry_04.pack(side="left", padx=(10, 0), pady=10, fill="x")
entry_05.pack(side="left", padx=(10, 0), pady=10, fill="x")
entry_06.pack(side="left", padx=(10, 0), pady=10, fill="x")
#===============BUTTONS===============#
button_01.pack(side="left", padx=(5, 0))
button_02.pack(side="left", padx=(5, 0))
#===============MAINLOOP===============#
root.mainloop()