Welcome to this article
By Caolán Maguire
Tkinter is Python’s standard GUI (Graphical User Interface) package and can be used to create graphical user interfaces (GUI’s) that can both serve as a simple application that uses toggle switches and buttons to do minor tasks or be used along with other packages to interact with hardware such as the GPIO pins on a raspberry pi or the GPIO pins on an Arduino.

NOTE: we will be using a Linux Fedora based machine in this blog, while most Linux based machines may use the same basic installation commands apart from some minor changes, we recommend you visit some of the links provided under the first heading to install Tkinter and then come back here to create a basic Tkinter program.

In today’s article we are going to run through how to :

  • How to install tkinter
  • How to install vim to edit and create python files
  • How to create a basic tkinter program
  • discuss how to make this program useful for businesses

1. Installing tkinter

so if you’re using a linux based machine then the install process is incredibly simple and is listed below, if you are using a windows or mac based machine however I’ve provided links to forums that have answered that question.

Installing Tkinter on fedora

First login as super user by issuing the following command:
su -
Then after filling in your password run the following command to check your python installation:
python3 -V

if you see the above result – you’re all set for the next instruction, if not run this command to install python3:
sudo apt-get install python3
next install tkinter in python 3:
yum install python3-tkinter
If there’s no problem there, we can get on to our next order of business.

Installing tkinter on Windows or mac

Here’s a great article I found for installing TKinter on windows
Here’s a great article I found for installing TKinter on mac

2. Installing vim to edit and create python files

This instruction isn’t actually all that necessary, you can create and edit python files in any text editor but I really recommend using vim, it’s fast and easy to use.
yum install vim

3. Create a basic Tkinter Program

This is where the fun begins. 🙂
So in this tutorial, I’m just going to include my complete program with a button included and some text, just to get you started. in the next tutorial, we’ll set up a Tkinter program that can interact with an Arduino. Here’s the code for my program below:

from tkinter import *

window = Tk()

window.title(“COMBILIFT CONTROL PANEL”)

window.geometry(‘1000×1200’)

lbl = Label(window, text=”COMBILIFT: CONTROL PANEL”)
i
lbl.grid(column=0, row=0)

btn = Button(window, text=”LIGHTS ON”, bg=”green”, fg=”white”)

btn.grid(column=1, row=0)

window.mainloop()

If you’ve followed the previous commands all you have to do is
create a directory
mkdir MyTkinterClass
Cd into that directory
cd MyTkinterClass
create a new python file
vim myclassfile.py
edit the file by pressing “i”, pasting in the code listed above, and then saving the file by pressing “:” then typing in “wq” and pressing enter to save this new file.
Finally all we have to do is run the new file in Python3
Python3 myclassfile.py

Done! we should be presented with the following popup window:

How Tkinter can be useful for businesses

If you’ve read through this whole post I’m sure you’ve come up with your own ideas and understandings of uses for this software around the work environment. I personally think a touchscreen interface along with some sort of linux based machine or development board, would be great to use with this, for example the raspberry pi could be used along side this and a few other packages to create a program that controls electronics and gadgets connected to it, for example you could connect this to the electrics in the house and use it to turn appliances on or off, or in an electronics company, use it as a quick wall mounted control panel or in the case of a motor company use it to control and measure sensors and controls from all over a car of vehicle.

Leave a comment

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.