Build a Professional BMI Calculator Using Python’s Tkinter

BMI Calculator 2.0

Creating real-world applications is one of the best ways to learn programming. In this guide, we will build a Body Mass Index (BMI) Calculator using Python and Tkinter, a popular library for creating graphical user interfaces (GUIs). This project is ideal for students and beginner programmers looking to enhance their Python skills.

What is BMI?

BMI (Body Mass Index) is a measurement of a person’s weight relative to their height. It is calculated using the formula:

BMI=Weight (kg)Height (m)2\text{BMI} = \frac{\text{Weight (kg)}}{\text{Height (m)}^2}

BMI categories are classified as follows:

  • Underweight: BMI < 18.5
  • Normal weight: BMI 18.5 – 24.9
  • Overweight: BMI 25 – 29.9
  • Obesity (Class 1): BMI 30 – 34.9
  • Obesity (Class 2): BMI 35 – 39.9
  • Extreme Obesity: BMI ≥ 40

Project Overview

This project features:

  • A user-friendly GUI for inputting weight and height.
  • Real-time BMI calculation and category display.
  • A professional design including company branding and a website link.

Prerequisites

Before starting, ensure you have Python installed. You can download it from python.org.

You also need some basic knowledge of Python and Tkinter.

Full Source Code

Below is the complete Python code for the BMI Calculator:

import tkinter as tk
from tkinter import messagebox
from tkinter import ttk

def calculate_bmi():
    """Calculate BMI and display the result."""
    try:
        weight = float(weight_entry.get())
        height = float(height_entry.get())
        
        if height <= 0 or weight <= 0:
            messagebox.showerror("Invalid Input", "Weight and height must be greater than zero.")
            return

        bmi = weight / (height ** 2)
        bmi = round(bmi, 2)
        category = bmi_category(bmi)
        
        result_label.config(text=f"Your BMI: {bmi}\nCategory: {category}", foreground="green")
    except ValueError:
        messagebox.showerror("Invalid Input", "Please enter valid numeric values for weight and height.")

def bmi_category(bmi):
    """Determine BMI category based on WHO classification."""
    if bmi < 18.5:
        return "Underweight"
    elif 18.5 <= bmi < 24.9:
        return "Normal weight"
    elif 25 <= bmi < 29.9:
        return "Overweight"
    elif 30 <= bmi < 34.9:
        return "Obesity (Class 1)"
    elif 35 <= bmi < 39.9:
        return "Obesity (Class 2)"
    else:
        return "Extreme Obesity"

def open_website():
    import webbrowser
    webbrowser.open("https://habitablesolution.com")

# Create the main application window
root = tk.Tk()
root.title("BMI Calculator")
root.geometry("400x400")
root.configure(bg="#f0f8ff")

# Header Section
header_frame = tk.Frame(root, bg="#4682b4", pady=10)
header_frame.pack(fill="x")

header_label = tk.Label(header_frame, text="BMI Calculator", font=("Helvetica", 20, "bold"), fg="white", bg="#4682b4")
header_label.pack()

# Website and Company Info
info_frame = tk.Frame(root, bg="#f0f8ff")
info_frame.pack(pady=10)

website_label = tk.Label(info_frame, text="Visit us: https://habitablesolution.com", font=("Helvetica", 10), fg="blue", cursor="hand2", bg="#f0f8ff")
website_label.pack()
website_label.bind("<Button-1>", lambda e: open_website())

company_label = tk.Label(info_frame, text="Provided by Habitable Solution", font=("Helvetica", 10), bg="#f0f8ff")
company_label.pack()

# Input Section
input_frame = tk.Frame(root, bg="#f0f8ff")
input_frame.pack(pady=10)

weight_label = tk.Label(input_frame, text="Weight (kg):", font=("Helvetica", 12), bg="#f0f8ff")
weight_label.grid(row=0, column=0, padx=10, pady=5, sticky="e")
weight_entry = ttk.Entry(input_frame, width=15)
weight_entry.grid(row=0, column=1, pady=5)

height_label = tk.Label(input_frame, text="Height (m):", font=("Helvetica", 12), bg="#f0f8ff")
height_label.grid(row=1, column=0, padx=10, pady=5, sticky="e")
height_entry = ttk.Entry(input_frame, width=15)
height_entry.grid(row=1, column=1, pady=5)

# Calculate Button
calculate_button = ttk.Button(root, text="Calculate BMI", command=calculate_bmi)
calculate_button.pack(pady=20)

# Result Section
result_frame = tk.Frame(root, bg="#f0f8ff")
result_frame.pack()

result_label = tk.Label(result_frame, text="", font=("Helvetica", 14), bg="#f0f8ff")
result_label.pack()

# Footer
footer_frame = tk.Frame(root, bg="#4682b4", pady=5)
footer_frame.pack(side="bottom", fill="x")

footer_label = tk.Label(footer_frame, text="Habitable Solution © 2025", font=("Helvetica", 10), fg="white", bg="#4682b4")
footer_label.pack()

# Start the Tkinter event loop
root.mainloop()

How to Run the Project

  1. Copy the code into a file named bmi_calculator.py.
  2. Ensure Python is installed on your computer.
  3. Run the script using an IDE or terminal.
  4. Interact with the user-friendly BMI Calculator interface!

BMI Calulaton 2.0 (HTML)

BMI Calculator Python Project

This is a practical Python project to calculate BMI using Tkinter. Learn how to build a graphical user interface and manage user inputs effectively.

Learning Outcomes

  • Understand GUI development using Tkinter.
  • Learn to handle user inputs and validations.
  • Gain experience with Python functions and modular code design.

Start building and customizing this project to enhance your skills. For more exciting projects and resources, visit us at Habitable Solution.

Write for Us

Love writing? Join Habitable Solution and share your ideas with our readers! We're always looking for fresh, engaging content.

How to Submit Your Article
1. Write on topics related to education, technology, entertainment, or current news.
2. Email your article to [email protected] with the subject “Guest Post: [Your Topic].”
3. Must Include a short author bio.

Start sharing your ideas today and inspire our readers!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Shopping Cart
Scroll to Top