Control your Rasp Pi projects with Python’s Tkinter library

If you are looking for an easy way to control your Raspberry Pi projects, consider Python's Tkinter library. In about 20 lines of Python code, you can create a graphic program to control a Rasp Pi rover project (Figure 1). This article shows how to create a Python Tkinter application to control the Rasp Pi's General Purpose Input Output (GPIO) pins. I will also show you how to set up a desktop shortcut that you can use to easily launch the application, and I will configure a Virtual Network Computing (VNC) server so that a smartphone, tablet, or PC can control the Rasp Pi remotely.

Figure 1: Tkinter-controlled rover.

Python Tkinter Library

Tkinter [1] is bundled with the standard Rasp Pi Python installation. The base Tkinter library contains 17 different widgets that you can use for graphic applications. These widgets can be defined with customizable colors, sizes, text, and commands. There are three geometry managers (Pack, Grid, and Place) that can be used to arrange the widgets. For Rasp Pi hardware projects, I found the Grid geometry manager was a good fit. Listing 1 is a simple test program that presents two buttons in a grid and prints feedback when the buttons are pressed. (Note: Python 2.7 references the library as Tkinter, whereas Python 3 uses tkinter, lowercase). Figure 2 shows this test program with some button feedback.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News