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 ...
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.