A comprehensive calculator built with Python and Tkinter featuring both basic and advanced mathematical operations.
- Addition (+)
- Subtraction (−)
- Multiplication (×)
- Division (÷)
- Modulus (mod)
- Percentage (%)
- Square root (√)
- Power operations (x², xʸ)
- Factorial (!)
- Logarithms (log, ln)
- Trigonometric functions (sin, cos, tan)
- Mathematical constants (π, e)
- Reciprocal (1/x)
- Clean and responsive GUI
- Large display screen for input and output
- History display showing previous calculation
- Comprehensive button layout with all functions
- Clear (C) and All Clear (AC) buttons
- Backspace functionality
- Dark/Light mode toggle
- Calculation history viewer
- Error handling for invalid operations
- Number keys (0-9) and numpad
- Basic operators (+, -, *, /, %)
- Parentheses ( )
- Decimal point (.)
- Enter/Return for calculation
- Escape for All Clear
- Backspace for deletion
- Python 3.6 or higher
- Tkinter (usually included with Python)
python advanced_calculator.pypython test_calculator.pyThe application follows object-oriented programming principles with clear separation of concerns:
- Handles all mathematical operations
- Manages calculation history
- Provides safe expression evaluation
- Processes special mathematical functions
- Manages the user interface
- Handles user input and display
- Implements keyboard shortcuts
- Manages themes and visual appearance
The calculator safely evaluates mathematical expressions using Python's eval() function with preprocessing to handle special symbols and functions.
Special functions like trigonometric operations, square roots, and factorials are processed using regular expressions and converted to appropriate Python math module calls.
Comprehensive error handling for:
- Division by zero
- Invalid expressions
- Mathematical domain errors (e.g., square root of negative numbers)
Toggle between light and dark modes using the moon/sun button in the interface.
View and clear calculation history through the dedicated History button.
- Basic Calculation:
2 + 3 * 4→14 - Advanced Functions:
sin(30) + cos(60)→1.0 - Complex Expression:
√(16) + 2²→8 - Factorial:
5!→120 - Logarithms:
log(100)→2
- Modular Design: Separate logic and UI classes
- Extensible: Easy to add new functions
- Maintainable: Clear code structure with comments
- User-Friendly: Intuitive interface with keyboard support
- Robust: Comprehensive error handling
The calculator provides a professional-grade experience suitable for both basic arithmetic and advanced mathematical calculations.