-
Notifications
You must be signed in to change notification settings - Fork 347
/
Copy pathage.py
36 lines (25 loc) · 846 Bytes
/
age.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
from tkinter import *
from datetime import datetime
from tkinter import messagebox
root = Tk()
root.title('Codemy.com - Age Calculator')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("500x300")
def age():
if my_entry.get():
# Get the current year
current_year = datetime.now().year
# Calculate The Age
your_age = current_year - int(my_entry.get())
# Show age in message box
messagebox.showinfo("Your Age", f"Your Age Is: {your_age}")
else:
# Show Error Message
messagebox.showerror("Error", "You forgot to enter your age!")
my_label = Label(root, text="Enter Year Born", font=("Helvetica", 24))
my_label.pack(pady=20)
my_entry = Entry(root, font=("Helvetica", 18))
my_entry.pack(pady=20)
my_button = Button(root, text="Calculate Age!", font=("Helvetica", 18), command=age)
my_button.pack(pady=20)
root.mainloop()