-
Notifications
You must be signed in to change notification settings - Fork 402
/
BMI.py
131 lines (107 loc) · 2.25 KB
/
BMI.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
from tkinter import *
from tkinter import messagebox
def reset_entry():
age_tf.delete(0,'end')
height_tf.delete(0,'end')
weight_tf.delete(0,'end')
def calculate_bmi():
kg = int(weight_tf.get())
m = int(height_tf.get())/100
bmi = kg/(m*m)
bmi = round(bmi, 1)
bmi_index(bmi)
def bmi_index(bmi):
if bmi < 18.5:
messagebox.showinfo('bmi-pythonguides', f'BMI = {bmi} is Underweight')
elif (bmi > 18.5) and (bmi < 24.9):
messagebox.showinfo('bmi-pythonguides', f'BMI = {bmi} is Normal')
elif (bmi > 24.9) and (bmi < 29.9):
messagebox.showinfo('bmi-pythonguides', f'BMI = {bmi} is Overweight')
elif (bmi > 29.9):
messagebox.showinfo('bmi-pythonguides', f'BMI = {bmi} is Obesity')
else:
messagebox.showerror('bmi-pythonguides', 'something went wrong!')
ws = Tk()
ws.title('BMI')
ws.geometry('400x300')
ws.config(bg='#686e70')
var = IntVar()
frame = Frame(
ws,
padx=10,
pady=10
)
frame.pack(expand=True)
age_lb = Label(
frame,
text="Enter Age (2 - 120)"
)
age_lb.grid(row=1, column=1)
age_tf = Entry(
frame,
)
age_tf.grid(row=1, column=2, pady=5)
gen_lb = Label(
frame,
text='Select Gender'
)
gen_lb.grid(row=2, column=1)
frame2 = Frame(
frame
)
frame2.grid(row=2, column=2, pady=5)
male_rb = Radiobutton(
frame2,
text = 'Male',
variable = var,
value = 1
)
male_rb.pack(side=LEFT)
female_rb = Radiobutton(
frame2,
text = 'Female',
variable = var,
value = 2
)
female_rb.pack(side=RIGHT)
height_lb = Label(
frame,
text="Enter Height (cm) "
)
height_lb.grid(row=3, column=1)
weight_lb = Label(
frame,
text="Enter Weight (kg) ",
)
weight_lb.grid(row=4, column=1)
height_tf = Entry(
frame,
)
height_tf.grid(row=3, column=2, pady=5)
weight_tf = Entry(
frame,
)
weight_tf.grid(row=4, column=2, pady=5)
frame3 = Frame(
frame
)
frame3.grid(row=5, columnspan=3, pady=10)
cal_btn = Button(
frame3,
text='Calculate',
command=calculate_bmi
)
cal_btn.pack(side=LEFT)
reset_btn = Button(
frame3,
text='Reset',
command=reset_entry
)
reset_btn.pack(side=LEFT)
exit_btn = Button(
frame3,
text='Exit',
command=lambda:ws.destroy()
)
exit_btn.pack(side=RIGHT)
ws.mainloop()