Drawing lines and arrows
One of the most basic actions you can perform with a canvas is drawing segments from one point to another. Although it is possible to directly draw polygons using other methods, the create_line
method of the Canvas
class has enough options to understand the basics of displaying items.
Getting ready
In this recipe, we will build an application that allows us to draw lines by clicking on the canvas. Each line will be displayed by clicking first on the point that will determine the line start, and a second time to set the line end.
We will be also able to specify some appearance options, such as color and width:

How to do it...
Our App
class will be responsible for creating an empty canvas and handling mouse click events.
The information on the line options will be retrieved from the LineForm
class. The approach of separating this component into a different class helps us to abstract its implementation details and focus on how to work with the Canvas
widget.
For the sake of...