Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

9.2. Coordinate System

A canvas widget uses a coordinate system to locate items inside of it, but the coordinate system isn't a normal one. It's more like an upside-down coordinate system.

Figure 9.1 shows a diagram that demonstrates the coordinate system a canvas widget uses.

Figure 9.1. Canvas coordinate system

The x coordinates behave normally; the larger coordinates are to the right and the smaller ones are to the left. The y coordinates look like they have been drinking vodka; the larger y coordinates are on the bottom rather than on the top because the 0,0 point is in the upper-left corner. Although it is rare, you can use negative coordinates in a canvas.

The coordinate system isn't too hard to deal with once you realize what is happening, but if you try to draw a building with a standard coordinate system in mind (that is, with the larger y coordinates higher up), your building will come out upside down.

There are several ways to deal with this. First, adjust your way of thinking so you always think y coordinates are larger at the bottom (never mind all those years we all struggled through geometry classes). Or, you are just as stubborn as I am, you can think in normal coordinates, and have your program do a quick little calculation before sending y coordinates to the canvas functions. (Multiply all y coordinates by -1. Tricky, huh?)

Whichever way you decide to deal with ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata