kcott has asked for the wisdom of the Perl Monks concerning the following question:

G'day All,

Background: I've been playing around in Tk, looking at the feasibility of using Tk::Canvas to generate some simple, interactive maps for use with RPGs. I came across the createGroup() method, which would help enormously with abstraction and code reduction; however, I'm unable to find any substantial documentation for this.

I found this method in "Mastering Perl/Tk" (Chapter 9: The Canvas Widget; The Group Item; pp. 212-213). Over half of that is taken up with a couple of screenshots. There's a minimal code example, with very little explanation, which looks like:

$one = $canvas->createOval(...); $two = $canvas->createRectangle(...); $group = $canvas->createGroup([0, 0], -members => [$one, $two]); $mw->update; $mw->after(1000); $canvas->move($group, 100, 100);

I've no idea what the [0, 0] is supposed to do. My first thought was that it was related to placement; but, after putting all sorts of different numbers in there, I see no change. It's also unclear why the update() is necessary — but it is.

I've checked for documentation, or other references, in the following places:

I put together the following test script. This was mainly to check that what was written in the book was valid.

#!/usr/bin/env perl use strict; use warnings; use Tk; my $mw = MainWindow::->new(); my $scrl_can = $mw->Scrolled('Canvas', -scrollregion => [0, 0, 300, 300], )->pack(qw{-fill both -expand 1}); my $c = $scrl_can->Subwidget('canvas'); for my $x (0, 100, 200) { my $grassy_creek = $c->createGroup( [0,0], -members => [grass($c), creek($c)] ); $mw->update(); $c->move($grassy_creek, $x, 100); } MainLoop; sub grass { return $_[0]->createRectangle( 0, 0, 100, 100, -fill => '#009900', -outline => undef ); } sub creek { return $_[0]->createRectangle( 0, 30, 100, 70, -fill => '#0000cc', -outline => undef ); }

That worked: I got (using a modicum of imagination) a creek running through a grassy area (three blocks wide). That's the type of abstraction I was looking for but I still wasn't happy with the cargo-cult programming.

I wondered if the ARRAYREF ([0, 0]) had something to do with the number of members in the group. I put a bend in the last part of the creek using a group with four members; this worked, still with [0, 0]. Here's the important part of the code for that test:

my $grassy_creek_bend = $c->createGroup( [0,0], -members => [ grass($c), creek_half_w($c), creek_half_s($c), creek_bend_ws($c), ] );

The full code is somewhat lengthy; it's in the following spoiler:

I'm using Perl 5.32.0 and Tk 804.035.

So, this leads to the questions. Can anyone point me to any documentation about this? In the absence of doco, does anyone have an explanation for the [0, 0] and the need for the update()?

Thanks in advance.

— Ken