Basic calculator with Python and Tkinter

Since I started learning python I always wanted to see my progress in a more graphical way like a program or anything that makes me feel like I'm learning something that can be useful. That is why in this my first article in medium, I will show you my first application using Tkinter that is a Python’s package de-facto standard GUI (Graphical User Interface) and if you are starting in the programming world and you’re feeling a little frustrated or with lack of motivation you can find some inspiration here to keep coding!
Basic Calculator
With this calculator, you will be able to do operations such as:
- Addition
- Subtraction
- Multiplication
- Division
And you can define the hierarchy of the operation using parentheses.
Now let’s break down the code
First of all, we need to import the Tkinter library and define the name of the main window of our application, this name will be showing at the top of the window.

Afterward, we need to define the main entry box where we will see all the operations that we’ll execute.

Then we need to define all the functions that will allow us to perform all the operations, let’s say these functions will be the brain of our application

Something that I’d like to highlight is the function “hacer_operacion”, instead of build every function for each one of the operations like addition, subtractions, etc. We will use the eval() function, in simple terms this function runs the python code (which is passed as an argument) within the program, in other words, the function will automatically identify if we want to perform a division, subtraction or any other mathematical operation.
Then we need to do is define and assign the right function to the buttons in our program.

The last thing that we need to do is design the buttons and how they will be shown on the screen of the program given the properties that we gave them.

Finally..
Save, run and play around your own calculator

You can see below the whole code you can just copy and paste it into any code editor and try it out.
Conclusion
In this article, I have described my first python project with a GUI (Graphical User Interface) this how I'm starting in my Python journey. Even though this is a very basic code you can use and modify it in order to create an advanced calculator application.