O'Reilly logo

Learning Perl/Tk by Nancy Walsh

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

9.9. Tags

Each item can also have a tag (or more than one tag) associated with it. We have seen tags used before in the text widget, where sections of text could be assigned a tag. A tag can be assigned when the item is created, or you can use the addtag method to assign a tag after the item has been created.

There are two special tags that are automatically assigned and maintained: the "current" and "all" tag. The "all" tag refers to all the items in the canvas. The "current" tag refers to the topmost item that the mouse cursor is over. If the mouse cursor is outside of the canvas widget or not over an item, then the "current" tag does not exist.

You can use tags to make changes to many different items at once. For instance, if you want all circles to have the same color, but you want to be able to change it from time to time, then give all circles a "circle" tag when you create them. Using the itemconfigure method to change the configuration options of the items with the "circle" tag.

The following are some sample syntax lines for creating tags.

$canvas->addtag("newtag", "above",tag/id);

The "newtag" tag is added to the item that is above the tag/ID item. If there is more than one match for tag/ID, the last item found will be used so the "newtag" is directly above the tag/ID item in the display list. The display list is created as you add items to the canvas and can be manipulated with the raise and lower methods.

$canvas->addtag("newtag", "all");

The keyword "all" is a special ...

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