Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BMI calculator project #262

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

126 changes: 126 additions & 0 deletions BMI calculator/Main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
from tkinter import *
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk

root = Tk()
root.title("BMI Calculator")
root.geometry("470x580+300+200")
root.resizable(False, False)
root.configure(bg="#1e1e1e") # Sfondo scuro

def BMI():
h = float(Height.get())
w = float(Weight.get())

m = h / 100
bmi = round(float(w / m**2), 1)
label1.config(text=bmi)

if bmi <= 18.5:
label2.config(text="Underweight!")
label3.config(text="Lower weight than normal body!")
elif 18.5 < bmi <= 25:
label2.config(text="Normal!")
label3.config(text="You are healthy!")
elif 25 < bmi < 30:
label2.config(text="Overweight!")
label3.config(text="You are slightly overweight!")
else:
label2.config(text="Obese!")
label3.config(text="Health may be at risk!")

# Icon
image_icon = PhotoImage(file="Sprites/bmiIcon.png")
root.iconphoto(False, image_icon)


# Mostra l'immagine in un'etichetta

top = PhotoImage(file="Sprites/Sif247.png")
top_image = Label(root, image = top, background="#f0f1f5")
top_image.place(x = -10, y=-10)

# Bottom box
Label(root, width=72, height=18, bg="#2a2a2a").pack(side=BOTTOM)

# Two boxes
box = PhotoImage(file="Sprites/box.png")
Label(root, image=box).place(x=20, y=100)
Label(root, image=box).place(x=240, y=100)

# Scale
scale = PhotoImage(file="Sprites/scale.png")
Label(root, image=scale, bg="#2a2a2a").place(x=20, y=310)

# Slider1
current_value = tk.DoubleVar()

def get_current_value():
return '{:.2f}'.format(current_value.get())

def slider_changed(event):
Height.set(get_current_value())
size = int(float(get_current_value()))
img = Image.open("Sprites/Man.png")
resized_image = img.resize((150, 30 + size))
photo2 = ImageTk.PhotoImage(resized_image)
secondimage.config(image=photo2)
secondimage.place(x=70, y=525 - size)
secondimage.image = photo2

style = ttk.Style()
style.configure("TScale", background="white")

slider = ttk.Scale(root, from_=0, to=220, orient='horizontal', style="TScale",
command=slider_changed, variable=current_value)
slider.place(x=80, y=250)

# Slider2
current_value2 = tk.DoubleVar()

def get_current_value2():
return '{:.2f}'.format(current_value2.get())

def slider_changed2(event):
Weight.set(get_current_value2())

style2 = ttk.Style()
style2.configure("TScale", background="white")

slider2 = ttk.Scale(root, from_=0, to=200, orient='horizontal', style="TScale",
command=slider_changed2, variable=current_value2)
slider2.place(x=300, y=250)

# Entry box
Height = StringVar()
Weight = StringVar()

Label(root, text="Height: cm", font='arial 12', bg='#1e1e1e', fg='#fff').place(x=35, y=130)
Label(root, text="Weight: kg", font='arial 12', bg='#1e1e1e', fg='#fff').place(x=255, y=130)


height = Entry(root, textvariable=Height, width=5, font='arial 50', bg='#444', fg='#fff', bd=0, justify=CENTER)
height.place(x=35, y=160)
Height.set(get_current_value())

weight = Entry(root, textvariable=Weight, width=5, font='arial 50', bg='#444', fg='#fff', bd=0, justify=CENTER)
weight.place(x=255, y=160)
Weight.set(get_current_value2())

# Man image
secondimage = Label(root, bg="#2a2a2a")
secondimage.place(x=70, y=530)

Button(root, text="View Report", width=15, height=2, font="arial 10 bold", bg="#3b5998", fg="white", command=BMI).place(x=280, y=340)

label1 = Label(root, font="arial 60 bold", bg="#2a2a2a", fg="#fff")
label1.place(x=250, y=400)

label2 = Label(root, font="arial 20 bold", bg="#2a2a2a", fg="#fff")
label2.place(x=250, y=480)

label3 = Label(root, font="arial 10 bold", bg="#2a2a2a", fg="#fff")
label3.place(x=250, y=550)

root.mainloop()
55 changes: 55 additions & 0 deletions BMI calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@


# BMI Calculator

BMI Calculator is a desktop application written in Python using the Tkinter library, which allows users to calculate their **Body Mass Index** (BMI) based on their height and weight. The user interface is designed to be intuitive and modern, with slider controls and dynamic visualization.

## Features

- BMI calculation based on height (in centimeters) and weight (in kilograms).
- Interactive adjustment of height and weight through sliders.
- BMI classification based on standard guidelines (underweight, normal, overweight, obese).
- Modern and user-friendly graphical interface with custom images and colors.
- Display of personalized health suggestions based on the BMI result.

## How It Works

1. Set your height using the slider on the left or manually enter the value in the "Height" field.
2. Set your weight using the slider on the right or manually enter the value in the "Weight" field.
3. Click the "View Report" button to calculate your BMI.
4. The result will be displayed at the bottom, along with a classification and health advice.

## Requirements

- **Python 3.x**
- **Tkinter** (usually pre-installed with Python)
- **Pillow** (for image handling)

To install Pillow, you can run:

```bash
pip install Pillow
```

## How to Run

1. Clone or download the project to your local directory.
2. Make sure you have the required dependencies installed.
3. Run the main Python file:

```bash
python bmi_calculator.py
```

## Project Structure

- **bmi_calculator.py**: The main file containing the application's logic and graphical interface.
- **Sprites/**: The folder containing all images used in the application, such as icons and backgrounds.

## Interface Example

<p align="center">
<img src="img/im1.png" alt="Image 1" width="250" style="margin-right: 10px;">
<img src="img/im2.png" alt="Image 2" width="250" style="margin-right: 10px;">
<img src="img/im3.png" alt="Image 3" width="250">
</p>
Binary file added BMI calculator/Sprites/Man.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BMI calculator/Sprites/Sif247.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BMI calculator/Sprites/bmiIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BMI calculator/Sprites/box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BMI calculator/Sprites/scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BMI calculator/img/im1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BMI calculator/img/im2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added BMI calculator/img/im3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.