Simple inputs. Handles two numbers and one operation at a time.
- Tested to work on Windows 11 properly. UI looks fine.
- Might not work well with Linux distributions
Download the latest .exe from releases. Works on windows and linux (using exe runner tools).
Everything starts from main.py
It creates the calculator window object, which further initializes the UI elements and the styling.
Clicking on any button calls the connector module which applies the logic behind that specific button.
Furthermore, the expressions are calculated using sympy.sympify() which parses and resolves the expressions. One important thing to note is that if the answer is a fraction, it will return the fraction as a string rather than a decimal number.
The code is mostly self-documented using python type hints and docstrings.
These bellow are details of what each module does. (click to expand)
./logic/
Logic for the functionality of the calculator. Basically, sub-modules that help perform calculations
./logic/operator
Main sub-module for calculation functions that solve expressions
./logic/expression
Expression class to "contain" the expression in two forms: a calculatable, and a displayable string
./ui/
Houses code for initializing, styling and handling UI
./ui/elements
This module has classes for each UI element the calculator has.
./ui/calculator
Main calculator file. Initializes the main app, it's layout, and calls functions to initialize it's elements
./ui/styling
Styling sub-module with functions to style elements of the calculator.
./connector
The bridge between the UI and the logic functions. This allows the UI to use the logic functions with adapter-style functions.
./engine
The boss. This is where the workflow starts running.
Any normal run of the calculator is done with 'python engine.py'. This file also decides whether to run the calculator in debug mode.
./exceptions
This module defines all kinds of exceptions that can occur in the app. Exceptions and their reason of occurence is documented with each function using google-style function docstrings.
./tests
This contains module-by-module tests for the codebase. Verifies that the modules are working properly with each other to carry out their expected functions.
- Clone this repository:
git clone https://github.com/ShahzaibAhmad05/calculator-python-
Make sure you have python 3.13 or above.
-
Create a virtual environment and activate it:
python -m venv .venv
# the activation command is different depending on OS, figure it out yourself- Install the requirements (only one):
pip install -r requirements.txt- Run from the engine file:
python main.pyThat's the GUI.