Skip to content

akarshxs/Calculator-GUI-with-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Calculator GUI – Python Tkinter

A simple and beginner-friendly Calculator Application built using Python and the Tkinter GUI toolkit.
This project demonstrates how buttons, events, layouts, and input handling work together in a graphical desktop application.


πŸ“Œ Features

  • Clean and simple user interface
  • Basic arithmetic: +, -, *, /
  • Decimal support
  • Parentheses support
  • Backspace button (←)
  • Clear button (C)
  • Real-time expression display
  • Error-safe evaluation
  • Beginner-friendly and easy to modify

πŸ“· Preview

The calculator window contains:

  • A numeric display screen
  • Buttons for numbers (0–9)
  • Buttons for + - * /
  • Buttons for ( and )
  • C for clearing
  • ← for backspace
  • = for calculation

🧠 How It Works

The app stores the current input in a variable called expression.
Each time a button is pressed, the character is added to the expression and displayed on the screen.

When = is pressed:

python result = str(eval(self.expression)) Python evaluates the entire expression. If something is wrong (like 2++3), the program shows "Error" instead of crashing.

πŸ“ Project Structure graphql Copy code calculator/ β”‚ β”œβ”€β”€ calculator.py # Main Tkinter GUI script └── README.md # Project documentation πŸ›  Requirements Python 3.x

Tkinter (usually pre-installed with Python)

▢️ How to Run Open your terminal or command prompt and run:

bash Copy code python calculator.py The calculator window will appear.

πŸ’‘ Code Overview 1️⃣ GUI Setup Creates the main window and display entry.

2️⃣ Buttons Buttons are placed using a list of tuples defining:

Button label

Row

Column

3️⃣ Event Handling on_button_click() processes clicks:

= β†’ evaluate

C β†’ clear

← β†’ delete last character

Other buttons β†’ append to expression

4️⃣ Evaluation Done with a simple eval() wrapped in a try-except:

python Copy code try: result = eval(self.expression) except: result = "Error" πŸš€ Future Improvements You can upgrade this project with:

Dark/light theme toggle

Scientific calculator buttons

Keyboard input support

History sidebar

Animated/hover buttons

πŸ“œ License You are free to use, modify, and distribute this code for learning or personal use.

less Copy code

If you want, I can also generate: βœ… A GitHub description section
βœ… Badges (Python version, Repo Stats, License, etc.)
βœ… A project banner image for your README
Just tell me!

About

Calculator GUI made with Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages