9.13. Changing the Display List

Every time a method looks through all the items in the canvas for a specific tag or ID, it looks through the display list. The display list is created as items are added to the canvas. The first item added to the canvas is the first item in the display list, and items are added in order as they are created. Also, items created later are drawn above the ones created earlier if they overlap at all. To change the display order, use the raise and lower methods:

$canvas->raise(tag/id, abovetag/id);
$canvas->lower(tag/id, belowtag/id);

The first argument for each method is the tag or ID of the item(s) you want to move in the display list. The second is the tag or ID next to which the first item should be placed (either above or below). If the first tag or ID matches more than one item, they are all moved.

Note that if you use the Scrolledmethod to create the canvas, you can't use the item returned by that method to invoke either raise or lower; you'll get a nasty error about the wrong argument types because Scrolledis not invoking this version of raise or lower, but another one. Use the subwidget to get the actual canvas reference and the call to raise and lower will work.

Get Learning Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.