O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

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

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.

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