Re: problem attaching balloons to tk::zinc items

On Tue, 10 Jan 2006 09:34:30 +1000, Matthew Braid <not@xxxxxxxxxxxxxxx>

>> I am trying to attach a couple of balloons to several items defined
>> within a zinc widget.
>> It doesn t work, tk::balloon seems to behave differently than for a
>> simple canvas.

>Doesn't Tk::Balloon have special 'canvas-spotting' code to enable use of
>a hash for the balloon message? Maybe since it's a Zinc and not a Canvas
>it doesn't recognise that a hash of messages can be used and uses the
>hash as a string instead.
>You might have to subclass Tk::Balloon and add code so that what it does
>for Tk::Canvas it also does for Tk::Zinc - probably something as simple as:
>if (ref($widget) eq 'Tk::Canvas' or ref($widget) eq 'Tk::Zinc') {...

Hi, I waited to see if there was an answer before I pulled this out, but
you can "roll-your-own". Here is a simple example. It actually is a
better solution ( over real balloons) because it is far more

use warnings;
use strict;
use Tk;
use Tk::Zinc;

my $mw = MainWindow->new();

my $zinc = $mw->Zinc()->pack;

my $item1 = $zinc->add('rectangle',1,[0,0,100,100],
-filled => 1,
-fillcolor => "blue",
-tags => ['item1','blue'],

my $item2 = $zinc->add('rectangle',1,[200,0,300,100],
-filled => 1,
-fillcolor => "red",
-tags => ['item2','red'],

$zinc->Tk::bind("<Motion>", [ \&print_xy, Ev('x'), Ev('y') ]);


sub print_xy {
my ($zinc, $x, $y) = @_;

#remove previous balloon

my $curr_object = $zinc->find('withtag','current');

my @list =();

if(defined $curr_object){
# print "curr->",@$curr_object,"\n"; #array dereference
(@list) = $zinc->gettags($curr_object);
# print "taglist->@list\n";
} else {return}

#make a label at mouse position
'text', 1,
-position => [ $x , $y - 15],
-color => 'yellow',
-text => "@list" ,
-tags =>['balloon'],


I'm not really a human, but I play one on earth.