Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Advanced Calculator GUI Application

A comprehensive calculator built with Python and Tkinter featuring both basic and advanced mathematical operations.

Features

Basic Operations

  • Addition (+)
  • Subtraction (−)
  • Multiplication (×)
  • Division (÷)
  • Modulus (mod)
  • Percentage (%)

Advanced Mathematical Functions

  • Square root (√)
  • Power operations (x², xʸ)
  • Factorial (!)
  • Logarithms (log, ln)
  • Trigonometric functions (sin, cos, tan)
  • Mathematical constants (π, e)
  • Reciprocal (1/x)

Interface Features

  • 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

Keyboard Support

  • Number keys (0-9) and numpad
  • Basic operators (+, -, *, /, %)
  • Parentheses ( )
  • Decimal point (.)
  • Enter/Return for calculation
  • Escape for All Clear
  • Backspace for deletion

Installation & Usage

Requirements

  • Python 3.6 or higher
  • Tkinter (usually included with Python)

Running the Calculator

python advanced_calculator.py

Testing the Logic

python test_calculator.py

Code Structure

The application follows object-oriented programming principles with clear separation of concerns:

CalculatorLogic Class

  • Handles all mathematical operations
  • Manages calculation history
  • Provides safe expression evaluation
  • Processes special mathematical functions

CalculatorGUI Class

  • Manages the user interface
  • Handles user input and display
  • Implements keyboard shortcuts
  • Manages themes and visual appearance

Key Features Explained

Expression Evaluation

The calculator safely evaluates mathematical expressions using Python's eval() function with preprocessing to handle special symbols and functions.

Function Processing

Special functions like trigonometric operations, square roots, and factorials are processed using regular expressions and converted to appropriate Python math module calls.

Error Handling

Comprehensive error handling for:

  • Division by zero
  • Invalid expressions
  • Mathematical domain errors (e.g., square root of negative numbers)

Theme Support

Toggle between light and dark modes using the moon/sun button in the interface.

History Management

View and clear calculation history through the dedicated History button.

Usage Examples

  1. Basic Calculation: 2 + 3 * 414
  2. Advanced Functions: sin(30) + cos(60)1.0
  3. Complex Expression: √(16) + 2²8
  4. Factorial: 5!120
  5. Logarithms: log(100)2

Architecture Benefits

  • 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages