O'Reilly logo

Python 2.6 Graphics Cookbook by Mike Ohlson de Fine

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

Converting an SVG path into a Tkinter Line

We take long and complex Inkscape-traced paths that are SVG encoded and convert them into Tkinter lines that can be displayed using methods like canvas.create_line(x0,y0, x1,y1, x2,y2, ...).

The following program takes a slightly edited form of a SVG path and transforms it into a form usable in a Tkintercreate_line() function.

To do this we need to exchange the single space characters that separate pairs of coordinates and replace them with commas.

At the same time, we want to convert the incremental coordinate values used by the SVG path into absolute values by adding the increment value to the corresponding previous value.

Getting ready

A typical SVG path for a 5-point line is shown below:

d="m 128,258 ...

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