This is my attempt to create a simple calculator using Python. I have tried to keep it easy to understand and have added comments throughout the code for clarity.
- tkinter – for the graphical user interface (buttons, display, frames).
- ast – used in the calculation part to convert the input expression into an Abstract Syntax Tree and then compile it for evaluation.
- Clear and simple code structure for easy customization.
- Button styles are defined once and reused throughout the interface.
- Designed with future expansion in mind – you can easily add more buttons or memory functions.
- Buttons are organized into two groups:
- Upper rows (functions) with one color.
- Lower rows (digits and operators) with another color for better readability.
- Run
calculator.pyto start the calculator. - Enter numbers and operations using the buttons and press
=to get the result. - Supports undo (
⌫) and clear (C) operations.
- Adding memory features (
M+,MR, etc.). - Adding more advanced mathematical functions.
- Adding a windows pin button to pin the calculator on the top screen which will be quite helpful in case of working with excel.
Happy Calculating!