Thursday, September 30, 2021

BMI Calculator using Python Tkinter module

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.

CategoryBMI range - kg/m2
Severe Thinness< 16
Moderate Thinness16 - 17
Mild Thinness17 - 18.5
Normal18.5 - 25
Overweight25 - 30
Obese Class I30 - 35
Obese Class II35 - 40
Obese Class III> 40


Below is the Python program and corresponding output window is shown.
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:

Link to Calculate BMI online: BMI Calculator

3 comments:

  1. All posts are good, keep posting such good articles

    ReplyDelete
  2. Just saw your repost on LinkedIn, maybe you can add a line with your status ("You are {status}"

    ReplyDelete

Some useful parameters

Dielectric constant  Metals have infinite Dielectric constant  As usually metals permittivity is very large than of free space hence its Die...