In this Python Tkinter Tutorial, I will help you learn to create a BMI Calculator using Python Tkinter.
Body Mass Index (BMI) is a simple calculation using a person’s height and weight. We will create a user-friendly GUI where users can enter their height and weight. This is a great beginner project to learn how to take input, perform calculations, and display results using Tkinter.
Let’s get in!
BMI Calculator using Python Tkinter
The formula is BMI = kg/m2, where kg is a person’s weight in kilograms and m2 is their height in meters squared. A BMI of 25.0 or more is overweight, while the healthy range is 18.5 to 24.9.
BMI Categories:
- Underweight = <18.5
- Normal weight = 18.5–24.9
- Overweight = 25–29.9
- Obesity = BMI of 30 or greater
Functions Explanation:
There can be many ways to create an interface for this program, but all the programs will have the same function. In this section, we will see how the main function works in this program. So there are two functions used to display the BMI result.
- calculate_bmi()
- bmi_index()
calculate_bmi():
- kg = int(weight_tf.get())
This line of code gets the user’s weight, converts it to an integer, and then stores the value in the variable kg - m = int(height_tf.get())/100
This line of code gets the user’s height, converts it into an integer, divides the result by 100 so that centimeters become meters, and then stores it in a variable m. - bmi = kg/(m*m)
This is the formula for finding BMI. We have stored the formula in a variable, BMI. - bmi = round(bmi, 1)
Before rounding off, the result appeared in multiple decimal values. But after using the round function, it looks simplified & easy to read.
Without the round function, the result appeared is 20.061728395061728, and after applying the round function, the result appeared is 20.1. - bmi_index(bmi)
We have called the bmi_index() function to compare the BMI value with the BMI categories.
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)bmi_index():
In this function, the final result is displayed depending on the BMI value & BMI category it belongs to.
BMI Categories:
- Underweight = <18.5
- Normal weight = 18.5–24.9
- Overweight = 25–29.9
- Obesity = BMI of 30 or greater
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!') Read Create an OptionMenu in Python Tkinter
Source Code:
Here is the complete source code of the BMI calculator. The code can be run on any version of python3 but it must have Tkinter installed. In case of any doubt or error, please leave a comment.
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('PythonGuides')
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()Output:
In this output, the user needs to fill in some information like age, gender, height & weight. Out of this information, height & weight are used to calculate the BMI. Then the BMI passes through conditions.
Each condition has a remark (underweight, Normal, overweight, etc). The result is displayed using a message box.

In this tutorial, I explained how to calculate BMI using Python Tkinter. I also discussed BMI categories, explained functions, along with source code.
You may like the following Python Tkinter tutorials:
- Create Layouts with Python Tkinter Frame
- Create a Progress Bar in Python Tkinter
- Master the Python Tkinter Canvas

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.