A simple BMI (Body Mass Index) calculator with a graphical user interface.
The project is organized following the separation of concerns principle:
- BMICalculator.py: Contains the user interface logic using Tkinter
- bmi_calculator_core.py: Contains the core BMI calculation logic
- test_bmi_core.py: Contains tests for the core functionality
- Calculate BMI based on weight (kg) and height (m)
- Display BMI category (Underweight, Normal weight, Overweight, Obesity)
- Color-coded results for better visualization
- Input validation with user-friendly error messages
- Support for both dot and comma as decimal separators
-
Make sure you have Python installed
-
Run the application:
python BMICalculator.py -
To run the tests:
python test_bmi_core.py
The application follows a clear separation between:
- UI Logic: Responsible for displaying the interface, handling user input, and presenting results
- Business Logic: Responsible for the actual BMI calculations, categorization, and input validation
This separation makes the code:
- More maintainable
- Easier to test
- More reusable (the core logic can be used in other interfaces)
The core module provides these main functions:
calculate_bmi(weight, height): Calculates BMI valueget_bmi_category(bmi): Determines the health category based on BMIget_category_color(category): Returns a color code for the categoryvalidate_input(weight_str, height_str): Validates user input
Potential enhancements for the future:
- Add support for imperial units (pounds, inches)
- Save history of calculations
- Provide more detailed health information
- Add data visualization for BMI trends
