This is a sophisticated, cross-platform desktop calculator built from the ground up in Python. It serves as a comprehensive portfolio piece demonstrating proficiency in GUI development, advanced software architecture, and secure, robust backend implementation.
Unlike simple calculator scripts, this project features a custom-built mathematical parser and Abstract Syntax Tree (AST) evaluator, eliminating the use of eval() entirely. It also utilizes multi-threading to ensure a fluid, non-blocking user interface.
| Dark Mode | Light Mode | Settings |
|---|---|---|
![]() |
![]() |
![]() |
| Calculation Example | Fraction Display | Solver Example |
|---|---|---|
![]() |
![]() |
![]() |
| Error Dialog |
|---|
![]() |
This project was engineered to professional standards, focusing on security, performance, and user experience.
-
Secure Custom Math Engine:
The core of the application. Instead of using the insecureeval()function, theMathEngineimplements its own tokenizer, parser, and Abstract Syntax Tree (AST) builder to safely process, interpret, and compute mathematical expressions. -
Asynchronous & Responsive GUI:
All calculations are executed in a separate worker thread (QObjectworker). This critical design choice ensures thePySide6main thread remains unblocked, providing a smooth, responsive user experience that never freezes, even during complex computations. -
Integrated Linear Equation Solver:
The math engine automatically detects expressions containing a variable (e.g.,x) and an equals sign. It then traverses the AST to algebraically solve forx, supporting full linear equations (5*x + 10 = 2*x - 2). -
High-Precision & Fraction Arithmetic:
To ensure mathematical accuracy, the engine uses Python'sDecimalmodule for all calculations, avoiding common floating-point inaccuracies. It also includes support forfractions, displaying results as exact fractions when appropriate. -
Modern Qt6 Interface (PySide6):
The UI is built withPySide6(the official Python bindings for Qt 6) and features:- A persistent settings dialog to manage application behavior.
- Full Dark Mode support.
- An intelligently resizing display font that adapts to long inputs and results.
- User-friendly features like Undo/Redo, clipboard integration, and button-hold detection.
-
Robust Error Handling:
A custom-defined hierarchy ofMathErrorexceptions (SyntaxError,CalculationError,SolverError) provides clear, user-friendly feedback for invalid syntax, division by zero, or non-linear problems. -
Configuration Management:
User preferences (like dark mode, decimal places) are saved to an externalconfig.jsonfile and managed by a dedicatedconfig_managermodule, demonstrating clean separation of concerns.
- GUI:
PySide6(Python for Qt 6) - Core Logic: Python 3,
Decimal,fractions,threading - Utilities:
pyperclip(cross-platform clipboard),pynput(key listener for modifiers like Shift) - Configuration:
json
- Python 3.7 or higher
pip(Python package installer)
-
Clone the repository:
git clone https://github.com/JanTeske06/Python_Calculator.git cd Python_Calculator -
Create a virtual environment (Recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the application:
python main.py
Python_calculator/
├── Modules/
│ ├── UI.py # Main GUI class (PySide6 window, widgets, signals)
│ ├── MathEngine.py # Core engine (Parser, AST, Solver, Evaluator)
│ ├── ScientificEngine.py # Handlers for sin, cos, log, etc.
│ ├── config_manager.py # Handles loading/saving settings from JSON
│ └── error.py # Custom error classes and error message dictionary
├── icons/
│ └── icon.png # Application icon
├── Screenshots/ # Screenshots used in this README
├── config.json # Stores user settings (persistent)
├── ui_strings.json # String definitions for the settings UI
├── main.py # Application entry point
├── requirements.txt # Python dependencies
└── README.md # Readme file
- Special thanks to Julian Theiling for his dedicated bug testing and valuable feedback during development.






