-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAge_Calc.py
More file actions
51 lines (40 loc) · 1.34 KB
/
Copy pathAge_Calc.py
File metadata and controls
51 lines (40 loc) · 1.34 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
from tkinter import *
from datetime import date
root = Tk()
root.geometry('280x300')
root.resizable(0,0)
root.title('Age Calculator')
statement = Label(root)
def ageCalc():
global statement
statement.destroy()
today = date.today()
birthDate = date(int(yearEntry.get()),int(monthEntry.get()),int(dayEntry.get()))
age = today.year - birthDate.year
if today.month - birthDate.month or today.month == birthDate.month and today.day < birthDate.day:
age -= 1
statement = Label(text=f'{nameValue.get()}s age is{age}.')
statement.grid(row=6,column=1,pady=15)
l1 = Label(text="Name:")
l1.grid(row=1,column=0)
nameValue = StringVar()
nameEntry = Entry(root,textvariable=nameValue)
nameEntry.grid(row=1,column=1,padx=10,pady=10)
l2 = Label(text="Year: ")
l2.grid(row=2,column=0)
yearValue = StringVar()
yearEntry = Entry(root,textvariable = yearValue)
yearEntry.grid(row=2,column=1,padx=10,pady=10)
l3 = Label(text="Month: ")
l3.grid(row=3,column=0)
monthValue = StringVar()
monthEntry = Entry(root,textvariable=monthValue)
monthEntry.grid(row=3,column=1,padx=10,pady=10)
l4 = Label(text="Day: ")
l4.grid(row=4,column=0)
dayValue = StringVar()
dayEntry = Entry(root,textvariable=dayValue)
dayEntry.grid(row=4,column=1,padx=10,pady=10)
button = Button(text="Calculate age", command=ageCalc)
button.grid(row=5,column=1)
root.mainloop()