The purpose of this project is purely educational. It aims to show, how to separate the business logic from the presentation layer using a variation of the Model-View-Controller pattern, in this case with Python and TKInter. Anyone with an interest should feel free to use it as a basis for their own experiments.
The TTK Calculator app itself is rather plain and straightforward implementation of a simple desk calculator.
It's been tested on recent (as of October 2024) versions of Windows, macOS and Ubuntu. For more information about the system requirements, please see the Installation chapter.
- Support of integers and decimals with a precision of up to 15 digits
- Addition (
+
), subtraction (-
), multiplication (×
) and division (÷
) of two numbers - Short evaluation (e.g. a sequence of button presses consisting of
9
×
=
will be translated to9
×
9
=
) - Result of a calculation can be automatically used as the first operand
of the next calculation (e.g. key sequence
9
×
9
=
+
9
=
will yield90
) - Inversion of a sign of the currently displayed number (
±
) - Correction / removal of last digit of the currently displayed number (
←
) - Reset of the calculator (e.g. after an error) is done via (
C
) button
Calculator can be operated by a mouse (left-click on the desired calculator button) or through a keyboard (see the user manual for a complete list of key bindings).
Make sure you have Python 3.12 or newer
installed on your system. Please note that the commands in the next chapters
use python
but your system may require you to type python3
instead.
Moreover, some Python installations (e.g. on Ubuntu or on macOS if installed trough
homebrew) by default do not contain TKInter Python package (usually called python3-tk
or python-tk
). You may need to use your package manager to check and possibly install
the missing package (e.g. sudo apt install python3-tk
on Ubuntu or
brew install python-tk
on macOS).
- Choose your installation folder and open it in a terminal emulator (a.k.a. command line) running cmd, powershell, bash, zsh or other sh-like shell.
- Clone the GitHub repository
If you don't have git installed, go back to the python_etudes GitHub repository page and download it as a zip archive file. Then extract its contents to an installation folder of your choice.
git clone https://github.com/slacker-by-design/python_etudes
- Run the calculator
cd python_etudes/ttkcalculator python -m ttkcalculator
- Choose your installation folder and clone the GitHub repository into it
- Create a Python virtual environment
cd ttkcalculator python -m venv venv
- Activate the virtual environment
- Linux & macOS
source venv/bin/activate
- Windows Powershell
.\venv\Scripts\Activate.ps1
- Windows CMD
venv\scripts\activate.bat
- Linux & macOS
- Install the
ttkcalculator
package as editablepython -m pip install -e .
- Make sure the
pytest
package is installed in your virtual environment The commandshould show a list of installed packages includingpython -m pip list
ttkcalculator
andpytest
. In casepytest
is missing, install it by typingpython -m pip install ".[test]"
- Run the tests
python -m pytest
Here's few more bits and pieces, which may be useful...
- You may want to check the TTK Calculator user manual
- The technical documentation contains a brief explanation of how the Model-View-Controller has been adopted in the case of TTK Calculator.