Categories

Developing simple GUI using “Tkinter” to control GPIO’s of Raspberry Pi

Hi, Welcome to your first Graphical User Interface(GUI) tutorial with Tkinter in Python to control GPIO’s of Raspberry Pi. In this tutorial, you will learn how to create a simple GUI using Tkinter.

Before getting started let us explain you some terms –

What Is A Graphical User Interface (GUI) ?

GUI is a graphical desktop app that helps you to interact with the computers. Here we will be creating GUI in Raspberry Pi which will be used to interact with its GPIO.

All the apps that we run on a computer are a type of GPIO.

  • GUI apps like Sudoku, Chess, Solitaire, etc.., are games that you can play.
  • GUI apps like Chrome, Firefox, Safari, etc.., are used to surf the Internet.

What Is Tkinter ?

Tkinter is an inbuilt Python module used to create simple GUI apps. It is the most commonly used module for GUI apps in the Python. You don’t need to worry about installation of the Tkinter module as it comes with Python default.

 

Step 1 – Making connections

  • Make connections as shown in the diagram below.

  • Here we will control Output for pins GPIO26 (Pin 37) and GPIO20 (Pin38) and will connect anode of the LED’s to them.
  • Pin no. 39 is used to provide ground.

Step 2 – Entering Code 

  • Open the python IDLE in Raspberry Pi and create a new Python file and enter the following code.

 

 

  • Working of each command mentioned in the corresponding comment.
  • Now save the program. We are saving it as gui_project python file.
  • Now open terminal and type command sudo python gui_project.py and press Enter.

  • Now the window naming My GUI will open up as shown.

  • Now you can control the pins with this graphical user interface. If you have touch display, you can also use it by touch.
  • Now you can yourself explore the world of GUI from Tkinter. For more help on tkinter visit : https://wiki.python.org/moin/TkInter

 

About the Author

abhishek@robu.in

Abhishek Thakur, Embedded Systems Enthusiast

Related Post

Submit a Review

Display Name

Email

Title

Message