While learning how to program in the Python programming language (specifically Python 3), one of the topics I was taught was the TKinter library in order to make graphical user interfaces. As part of the course I was taking, I had to submit a moderately complex project that used this library. In my case, I chose to make a calculator application similar to the one that you might find in Microsoft Windows. This would be a simple program with multiple buttons. Each button would represent a number or a function that the could press them to make a calculation. Any result could then be used to make new a calculation.

image

The Windows 7 calculator was the inspiration for the project

This functionality made the project appealing because it had a large user interface, and the actual function of the application was very simple. Therefore the main focus could be on the graphical interface rather than the output of the program. To accomplish this functionality, I wrote a class that encapsulated the function and interface of a single button. This class could be replicated across multiple locations, and since each class contained its own independant functionality, it was trivial to assign different operations to each button. The special buttons were programmed differently, as it became nessesary to store and retrieve the result of the calculator as a string of characters. This format made it possible to delete the last input character (DEL) and clear the stored input (CE).

The Python calculator looked basic but it worked

This allowed the calculator to perform basic operations such as addition, subtraction, multiplication and division. It effectively mimmicked a cheap hand-held calculator. In the end, this was a nice project that taught me a lot about how to make graphical interfaces. It was not complex but it did highlight the importance of factoring graphical elements to reuse them later.

Github repository

To use the calculator, simply execute “simple_calc.py” with the python shell. The repository can be found here: Calculator-GUI