-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask-2
More file actions
43 lines (34 loc) · 1.16 KB
/
Copy pathTask-2
File metadata and controls
43 lines (34 loc) · 1.16 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
import tkinter as tk
root = tk.Tk()
root.title("BMI Calculator")
root.geometry("400x400")
label = tk.Label(root, text = "Enter your weight(Kg): ")
label.pack()
entry_weight = tk.Entry(root, width=30)
entry_weight.pack()
label1 = tk.Label(root, text = "Enter your height(Meter): ")
label1.pack()
entry_height = tk.Entry(root, width=30)
entry_height.pack()
def calculate_bmi():
try:
weight = float(entry_weight.get())
height = float(entry_height.get())
bmi = weight / (height * height)
category = " "
if bmi < 18.5:
category = "Underweight"
elif bmi >= 18.5 and bmi <=24.9:
category = "Normal Weight"
elif bmi >= 25 and bmi <= 29.9:
category = "Over Weight"
else:
category = "Obese"
result_label.config(text= f"Your BMI is : {bmi:.5f}\nYou are {category}")
except ValueError:
result_label.config(text = "Please enter valid numbers!" )
button = tk.Button(root, text = "Get my BMI", command = calculate_bmi )
button.pack()
result_label = tk.Label(root, text="")
result_label.pack()
root.mainloop()