#!/usr/bin/perl use strict; use warnings; use Data::Dumper qw/Dumper/; use Tk; my $mw = tkinit(); my $c = $mw->Canvas()->pack(-expand => 1, -fill => 'both',); # ------------------------------------------------------------- # --- left box my $left = $c->createText( 50, 50, -text => 'left', -tags => [qw/left text id1/] ); my @left_bbox = $c->bbox('left', 'id1'); my $padding = 3; $c->createRectangle( $left_bbox[0] - $padding, $left_bbox[1] - $padding, $left_bbox[2] + $padding, $left_bbox[3] + $padding, -fill => 'green', -tags => [qw/left box id1/] ); $c->raise('text', 'box'); # ------------------------------------------------------------- # --- right box my $right = $c->createText( 250, 50, -text => 'right', -tags => [qw/right text id5/] ); my @right_bbox = $c->bbox('right', 'id5'); $c->createRectangle( $right_bbox[0] - $padding, $right_bbox[1] - $padding, $right_bbox[2] + $padding, $right_bbox[3] + $padding, -fill => 'yellow', -tags => [qw/right box id5/] ); $c->raise('text', 'box'); $mw->MainLoop();