|
8 | 8 |
|
9 | 9 | # importing tkinter |
10 | 10 | import tkinter as tk |
| 11 | +from tkinter import messagebox |
11 | 12 |
|
12 | 13 | class BmiCalculator: |
13 | 14 | def __init__(self): |
@@ -62,27 +63,36 @@ def findBMI(self): |
62 | 63 | elif self.isValidDecimal(weight)==True and self.isValidDecimal(height)==True: |
63 | 64 | # converted height in centimetre to metre |
64 | 65 | heightMetre = float(height)/100 |
65 | | - # calculating bmi |
66 | | - bmi = float("{:.2f}".format(float(weight)/heightMetre/heightMetre)) |
67 | | - # Displaying bmi through label 'bmiLabel' |
68 | | - self.bmiLabel.config(text=f"BMI is {bmi}") |
69 | | - # Category of BMI result |
70 | | - if bmi<15: |
71 | | - self.result.config(text="Very severely underweight",bg="purple",fg="white",font=("Georgia")) |
72 | | - elif bmi>=15 and bmi<16: |
73 | | - self.result.config(text="Severely underweight", bg="blue", fg="white",font=("Georgia")) |
74 | | - elif bmi>=16 and bmi<18.5: |
75 | | - self.result.config(text="Underweight", bg="#3377ff", fg="black",font=("Georgia",18)) |
76 | | - elif bmi>=18.5 and bmi<=24.9: |
77 | | - self.result.config(text="Healthy", bg="green", fg="white",font=("Georgia",20)) |
78 | | - elif bmi>=25 and bmi<=29.9: |
79 | | - self.result.config(text="Overweight", bg="yellow", fg="black",font=("Georgia",20)) |
80 | | - elif bmi>=30 and bmi<40: |
81 | | - self.result.config(text="Obese", bg="orange", fg="black",font=("Georgia",20)) |
82 | | - elif bmi>=40: |
83 | | - self.result.config(text="Extremely Obese", bg="red", fg="white",font=("Cambria",23)) |
| 66 | + if float(height)>=100 and (weight!=0.0 or weight!=0): |
| 67 | + # calculating bmi |
| 68 | + bmi = float("{:.2f}".format(float(weight)/heightMetre/heightMetre)) |
| 69 | + # Displaying bmi through label 'bmiLabel' |
| 70 | + self.bmiLabel.config(text=f"BMI is {bmi}") |
| 71 | + # Category of BMI result |
| 72 | + if bmi<15: |
| 73 | + self.result.config(text="Very severely underweight",bg="purple",fg="white",font=("Georgia")) |
| 74 | + elif bmi>=15 and bmi<16: |
| 75 | + self.result.config(text="Severely underweight", bg="blue", fg="white",font=("Georgia")) |
| 76 | + elif bmi>=16 and bmi<18.5: |
| 77 | + self.result.config(text="Underweight", bg="#3377ff", fg="black",font=("Georgia",18)) |
| 78 | + elif bmi>=18.5 and bmi<=24.9: |
| 79 | + self.result.config(text="Healthy", bg="green", fg="white",font=("Georgia",20)) |
| 80 | + elif bmi>=25 and bmi<=29.9: |
| 81 | + self.result.config(text="Overweight", bg="yellow", fg="black",font=("Georgia",20)) |
| 82 | + elif bmi>=30 and bmi<40: |
| 83 | + self.result.config(text="Obese", bg="orange", fg="black",font=("Georgia",20)) |
| 84 | + elif bmi>=40: |
| 85 | + self.result.config(text="Extremely Obese", bg="red", fg="white",font=("Cambria",23)) |
| 86 | + elif heightMetre==0 or weight==0: |
| 87 | + self.bmiLabel.config(text="") |
| 88 | + self.result.config(text="Height and Weight cannot be 0", bg="red", font=("Arial", 15)) |
| 89 | + else: |
| 90 | + # When entered height is less than 100 |
| 91 | + self.bmiLabel.config(text="") |
| 92 | + self.result.config(text="", bg="#ccffff") |
| 93 | + messagebox.showinfo(title="Message",message="Invalid height and weight") |
84 | 94 | else: |
85 | | - # When the entered input in height and weight fiels is not numbers |
| 95 | + # When the entered input in height and weight fields is not number |
86 | 96 | self.bmiLabel.config(text="") |
87 | 97 | self.result.config(text="Enter numbers only please",bg="red",font=("Arial",18)) |
88 | 98 | # object created for the class 'BmiCalculator' |
|
0 commit comments