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 they take the tag or ID of the item(s) as a first argument. We
say “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 replaces any currently set
tags for the item. The taglist associated
with -tags can also be empty, which will
essentially remove all tags.
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.
Read now
Unlock full access