Project Background

Building a Health Metrics Calculator GUI

Transforming Python functions into an interactive desktop application with PyQt5

Part 2 of 2: GUI Development

TL;DR

I wrapped the calculation engine from Part 1 in a PyQt5 graphical interface, creating a desktop application where users input their metrics through form fields and receive instant results. The GUI uses 5 different widget types (text inputs, radio buttons, dropdowns, buttons, and display areas) to collect data and present all 7 health metrics in a clean, formatted output.

The Objective

The back-end functions from Part 1 work perfectly in a Python console, but asking users to run scripts and type function calls isn't practical. A graphical interface removes this barrier entirely.

Goal: Build a user-friendly desktop application that collects health data through intuitive form controls and displays calculated metrics without requiring any coding knowledge from the user.

Tech Stack & Context

Framework: PyQt5 (Python bindings for Qt)
Integration: Imports health_metric function from Part 1 module
Limitation: No input validation on modular functions. This means it will accept any text string or integers

PyQt5 Widgets Used

Each input type was matched to the most appropriate widget for usability:

QLineEdit
Text input for weight, height, age
QRadioButton
Binary choice for sex selection
QComboBox
Dropdown for activity level
QPushButton
Triggers calculation
QTextEdit
Read-only results display
QLabel
Field labels and headings

My Approach

I tried to structure the GUI as it will appear to the user. Starting with the input widgets, connecting them to the backend functions, and ending with the output display.

1
Set up the base application: Initialized QApplication and QWidget, set dimensions (400×570px), title, and created a vertical layout container for all elements.
2
Built input widgets: Created QLineEdit fields for weight/height/age, QRadioButtons for sex (grouped with QButtonGroup), and a QComboBox dropdown with 5 activity levels.
3
Created translation function: The dropdown returns strings like "1 = Sedentary" but our function needs integers. Built a helper function to convert these to the required 1-5 values.
4
Wired the processing logic: Connected the Run button to a function that extracts all inputs, converts types appropriately, calls the health_metric function, and displays results in a read-only QTextEdit.
Key decision: I used a separate translation function for the activity dropdown rather than storing just integers. This keeps the dropdown user-friendly ("Moderately active" is clearer than "3") while maintaining clean separation between UI labels and data values.
Health Metrics Calculator GUI
Figure 1: Complete GUI Application The finished interface showing all input fields, the Run button, and the formatted results display area with calculated health metrics.

Key Outcomes

5 Inputs → 7 Outputs

Users input just 5 fields and receive all health metrics instantly in a formatted, easy-to-read display area.

Clean Separation of Concerns

GUI code handles presentation only. All calculation logic stays in the imported Part 1 module, making both easier to maintain & debug.

Back to Part 1: Back-End Development

Reflection

Building this GUI taught me how important it is to plan widget-to-function mapping before writing code. The dropdown translation issue, for example, would have been avoided with better upfront design.

Future improvements would include: adding input validation (preventing negative numbers or text in numeric fields), implementing unit conversion toggles (metric/imperial), and perhaps adding visual charts to display results graphically rather than as text only.

Tools & Technologies

Python PyQt5 QWidgets Modular Imports