Real Python

Breaking into the industry: My journey to becoming a Software Engineer #4 — Python GUI Programming with Tkinter

M E
3 min readJul 6, 2021

--

In this episode of “becoming a Software Engineer,” I built my first ever Python GUI (“Gee-You-Eye”). Don’t make the same mistake as me, I have been calling it “Gooeey.”

Let’s drive down to memory lane real quick: I remember driving from Seattle to Canada and my rental car did not have a mile-km feature in the odometer. As you all know, the United States is one of the only three countries in the world that uses the Imperial System. So while driving around Canada and I saw the speed limit, I pulled out my phone right away to convert miles to kilometer. And let me tell you, it was not easy constantly converting what my speed (in miles) to kilometer. I did not want to get a speeding ticket! This GUI application would have been useful for me at that time.

Anyways, let’s get back to the topic. So, I created a GUI application using Tkinter. It basically asks the user to enter the desired number (in miles) that they want to convert to kilometer.

Check out the rest of the code on my GitHub account: Mile to Km Converter

The function mile_km_converter() is called as a command whenever the “calculate” button is clicked. Inside the mile_km_converter() is where the “input” value is used to multiply by 1.609344 (1 mile = 1.609344 km), it then changes the value of the “new_number” label (what is shown after the words “equal to”) and then displays the “new_number” value.

Now the next time I travel to countries that uses the Metric System, this GUI app will come in handy.

Hey Siri, play The 50 States Song

I also created a GUI application to help memorize all the 50 states.

This app is great for learning!

  • User must enter any state’s name (the user input will be automatically converted to .title()) so it doesn’t matter if enter the text in lower or uppercase.
  • User must enter the correct spelling of the state’s name or else it will be deemed as wrong and must re-enter their answer again.
  • When the user is stuck and can no longer think of any other state’s name, then they can type the word “exit,” and the program will end and generate a csv file called “states_to_learn.csv” that will contain all of the states name the user did not guess.
  • When a user input their answer, it will be automatically placed on the correct location of the state mentioned.
If the user input is in the state data list, it will access the 50_states.csv file to get the x and y coordinates of that specific state and the turtle object will write the user input to be displayed on screen.
Snippet of the 50_states.csv file with the State’s name and their x and y coordinates
Check out the rest of the code on my GitHub Account: us-state-game

--

--