9.8. Configuring Items in the Canvas Widget

To change the configuration options of any of the items within the canvas, you only need to know the tag name or the ID for that item. You can then use the itemcget and itemconfigure methods. They behave just like the cget and configure methods, except as a first argument, they take the tag or ID of the item(s). I use the term "item(s)" because a tag can refer to more than one item. Here are some examples:

$color = $canvas->itemcget("circle", -fill);
$canvas->itemconfigure($id_number, -fill => "yellow", -outline => 5);

Make sure the options you use with itemconfigure and itemcget are valid. Each item type has a list of valid options; they are listed earlier in this chapter with each create method.

When you set the -tags option, the itemconfigure method will replace any currently set tags for the item. The taglist associated with -tags can also be empty, which will essentially remove all tags.

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.