This is a basic calculator implemented in Python using the Tkinter library.
- Run the script (
calculator.py
). - The calculator window will appear, displaying an entry widget at the top for input and output.
- Use the numeric buttons (0-9) and arithmetic operators (+, -, *, /) to input your expression.
- Press the "=" button to calculate the result.
- Press the "C" button to clear the entry.
- If there's an error in the input expression, "Error" will be displayed.
on_click(value)
: Appends the clicked button's value to the current input in the entry widget.clear_entry()
: Clears the entry widget.calculate()
: Evaluates the expression in the entry widget and displays the result. Handles errors gracefully.
The calculator has the following buttons:
- Digits: 0-9
- Arithmetic Operators: +, -, *, /
- Other: . (decimal point), = (equals), C (clear)
- Python 3.x
- Tkinter (included in most Python installations)
Make sure you have Python installed on your system. Then, run the script using the following command:
python calculator.py
- This calculator supports basic arithmetic operations.
- The code uses the eval() function to evaluate expressions, so avoid using it with untrusted input.
- Feel free to modify and enhance the code according to your needs!