-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson_class.py
74 lines (57 loc) · 1.91 KB
/
person_class.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
# Create a class called person
# create init method
import datetime
import tkinter as tk
from PIL import Image, ImageTk
# Create frame
window = tk.Tk()
# Create geometry frame
window.geometry("350x350")
# Set the title of the frame
window.title("Age Calculator")
# Adding Labels
year_label = tk.Label(text="Year")
year_label.grid(column=0, row=1)
month_label = tk.Label(text="Month")
month_label.grid(column=0, row=2)
day_label = tk.Label(text="Day")
day_label.grid(column=0, row=3)
year_entry = tk.Entry()
year_entry.grid(column=1, row=1)
month_entry = tk.Entry()
month_entry.grid(column=1, row=2)
day_entry = tk.Entry()
day_entry.grid(column=1, row=3)
def calculate_age():
print(year_entry.get())
print(month_entry.get())
print(day_entry.get())
person = Person("Hassan", datetime.date(int(year_entry.get()),
int(month_entry.get()),
int(day_entry.get())))
print(person.age())
text_answer = tk.Text(master=window,height=10, width=30)
text_answer.grid(column=1, row=5)
answer_text = "{name} is {age} years old".format(name=person.name, age=person.age())
text_answer.insert(tk.END, answer_text)
# Adding a button
calc_button = tk.Button(text="Calculate", command=calculate_age)
calc_button.grid(column=1, row=4)
class Person:
def __init__(self, name, birthdate):
self.name = name
self.birthdate = birthdate
def age(self):
today = datetime.date.today()
age = today.year - self.birthdate.year
return age
image = Image.open('/Users/pujeh/Desktop/Python_learning/ageimage.jpg')
image.thumbnail((200, 200), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(image)
label_image = tk.Label(image=photo)
label_image.grid(column=1, row=0)
#person = Person("Hassan", datetime.date(1992, 7, 5))
# print(Lansana.name)
# print(Lansana.birthdate)
# print(Lansana.age())
window.mainloop()