Skip to content

LakshyaSharma2005/Python-Assignment-6-GUI-Calculator-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฎ Calculator App (Tkinter)

A simple and elegant GUI Calculator built using Pythonโ€™s Tkinter library. This calculator supports basic arithmetic operations along with percentage handling, delete, and clear functionalities โ€” all wrapped in a clean UI.


๐Ÿš€ Features

โœ… Basic arithmetic operations โ€” +, -, x, / โœ… Percentage calculations (%) with enhanced logic โœ… C (clear) and del (delete last character) functions โœ… Error handling for invalid expressions โœ… Read-only display to prevent unwanted edits โœ… Modern layout with clear, large buttons


๐Ÿงฉ How It Works

The calculator uses a single event handler function (calculator) that binds to all buttons. When a button is clicked, the text from that button is fetched and evaluated through logic that:

  1. Builds expressions dynamically.
  2. Replaces x with * for Pythonโ€™s evaluation.
  3. Converts percentage (%) into valid mathematical expressions using regex.
  4. Evaluates safely using eval() inside a try-except block.

๐Ÿง  Percentage Logic

The app supports expressions like:

Expression Interpreted As Result
50% 50/100 0.5
10%100 (10/100) * 100 10
50+10%50 50 + (10/100)*50 55

This makes the percentage operation work more like a real calculator.


๐Ÿ–ฅ๏ธ UI Layout

  • Entry widget (display): Shows the expression/result

  • Button grid (5x4): Number keys, operators, and function keys

  • Color-coded buttons:

    • Orange โ†’ Operator or control (C, %, /, x, -, +, =)
    • Gray โ†’ Number buttons

โš™๏ธ Requirements

  • Python 3.x
  • Tkinter (comes pre-installed with Python)

โ–ถ๏ธ How to Run

  1. Clone this repository:

    git clone https://github.com/LakshyaSharma2005/tkinter-calculator.git
  2. Navigate into the folder:

    cd tkinter-calculator
  3. Run the script:

    python calculator.py

๐Ÿ“ธ Screenshot (Optional)

image

๐Ÿง‘โ€๐Ÿ’ป Author

Lakshya Sharma ๐Ÿ”— GitHub: @LakshyaSharma2005 ๐Ÿ’ฌ Contributions, suggestions, and forks are welcome!


๐Ÿ“œ License

This project is open-source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages