Using Python's Tkinter module, here I have implemented a BMI calculator.
BMI introduction
BMI is a measurement of a person's leanness or corpulence based on their height and weight, and is intended to quantify tissue mass. It is widely used as a general indicator of whether a person has a healthy body weight for their height. Specifically, the value obtained from the calculation of BMI is used to categorize whether a person is underweight, normal weight, overweight, or obese depending on what range the value falls between.
BMI table for adults
This is the World Health Organization's (WHO) recommended body weight based on BMI values for adults. It is used for both men and women, age 18 or older.
Category | BMI range - kg/m2 |
Severe Thinness | < 16 |
Moderate Thinness | 16 - 17 |
Mild Thinness | 17 - 18.5 |
Normal | 18.5 - 25 |
Overweight | 25 - 30 |
Obese Class I | 30 - 35 |
Obese Class II | 35 - 40 |
Obese Class III | > 40 |
from tkinter import *
def bmi_calci():
weight = float(weight_input.get())
height = float(height_input.get())
res = round((weight/(height*height))*10000, 2)
bmi_result_label.config(text=f"{res}")
window = Tk()
window.title("BMI Calculator")
window.minsize(width=250, height=150)
window.config(padx=20, pady=20)
weight = Label(text="Weight is")
weight.grid(column=0, row=0)
height = Label(text="Height is")
height.grid(column=0, row=1)
weight_input = Entry(width=12)
weight_input.grid(column=1, row=0)
height_input = Entry(width=12)
height_input.grid(column=1, row=1)
weight_label = Label(text="KG")
weight_label.grid(column=2, row=0)
height_label = Label(text="CM")
height_label.grid(column=2, row=1)
bmi_label = Label(text="Your BMI is ")
bmi_label.grid(column=0, row=2)
bmi_result_label = Label(text="0")
bmi_result_label.grid(column=1, row=2)
bmi_unit_label = Label(text="Kg/m^2")
bmi_unit_label.grid(column=2, row=2)
calculate_button = Button(text="Calculate", command = bmi_calci)
calculate_button.grid(column=1, row=3)
window.mainloop()
Output Window: