Tk's widget demo has precisely what you want, in "The canvas item types" demo. It also lets you see the code.
Basically, you want to use Tk::Canvas' createWindow command to display a child widget in the canvas:
use Tk;
my $mw = new Tk::MainWindow;
my $c = $mw->Canvas(-width => 300, -height => 100)->pack;
my $text = $c->createText(20, 20, -text => 'A text item');
my $but = $c->Button(-text => 'Push me!',
-command => sub {
colour_text('red');
$mw->after(500, [\&colour_text => 'black']);
},
);
my $but_i = $c->createWindow(70, 50, -window => $but);
MainLoop;
sub colour_text {
my $colour = shift;
$c->itemconfigure($text, -fill => $colour);
}
| [reply] [d/l] [select] |