O'Reilly logo

Raspberry Pi Cookbook for Python Programmers by Tim Cox

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Drawing lines using a mouse on Tkinter Canvas

The Tkinter Canvas widget provides an area to create and draw objects on. The following script demonstrates how to use mouse events to interact with Tkinter. By detecting the mouse clicks, we can use Tkinter to draw a line that follows the movement of the mouse.

Drawing lines using a mouse on Tkinter Canvas

A simple drawing application using Tkinter

Getting ready

As before, we need to have Tkinter installed and either the Raspbian desktop running (startx from the command line) or an SSH session with X11 Forwarding and an X server running (see Chapter 1, Getting Started with a Raspberry Pi Computer). We will also need a mouse connected.

How to do it… ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required