It gets kind of exasperating when someone wants answers to a relatively complex operation, and they don't give a working code example. The way you posted little snips of code, I've had to spend more time just trying to make it a running script, in order to test it. So, here is how I would have done it. It appears that the group in Tk::Canvas gets in the way. In Zinc, the group is very powerful and useful, but in the plain old Canvas, the group item is just not very useful. I switched to just using plain tags...like I said before "tags are the key to making complex interactions".
#!/usr/bin/perl use warnings; use strict; use Tk; my $dx; my $dy; my $grouptag; my $mw = MainWindow->new; $mw->geometry("700x600"); my $x1 = 10; my $x2 = 20; my $c = $mw->Canvas(-width => 700, -height => 565, -bg => 'black', )->pack; my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exi +t(0)}) ->pack; my $parent = $c->createRectangle(10, 20, 100, 60, -fill => 'red', -tags => ['mover','group1'], ); my @children; for (1..4) { push @children, $c->createRectangle($x1, 20, $x2, 30, # -state =>'disabled', -fill => 'white', -activefill => 'green', -disabledfill => 'white', -tags => ['mover','group1'], ); $x1 += 15; $x2 += 15; } # #my $group = $c->createGroup([0, 0], # -members => [$parent, @children]); # #$c->bind($group, '<1>', sub {&mobileStart();}); #$c->bind($group, '<B1-Motion>', sub {&mobileMove();}); #$c->bind($group, '<ButtonRelease>', sub {&mobileStop();}); $c->bind('mover', '<1>', sub {&mobileStart();}); $c->bind('mover', '<B1-Motion>', sub {&mobileMove();}); $c->bind('mover', '<ButtonRelease>', sub {&mobileStop();}); MainLoop; sub mobileStart { my $ev = $c->XEvent; ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); my $curr_object = $c->find('withtag','current'); print "curr->",@$curr_object,"\n"; #array dereference my (@list) = $c->gettags($curr_object); print "movelist->@list\n"; ($grouptag) = grep /(group\d+)/, @list; print "grouptag-> $grouptag\n"; print "START MOVE-> $dx $dy\n"; } sub mobileMove { my $ev = $c->XEvent; $c->move($grouptag, $ev->x + $dx, $ev->y +$dy); ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); print "MOVING-> $dx $dy\n"; } sub mobileStop{&mobileMove;}

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

In reply to Re: Tk-Canvas Grouping by zentara
in thread Tk-Canvas Grouping by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.