Right. So your issue is retrieving a reference to the canvas object. The easiest approach would probably be to store a reference to it when you create it. You seem to be creating a module anyway...so perhaps something like:
package YourPackage;
use strict;use warnings;
use Tk;
use Tk::Canvas;
sub new {
my $class = shift;
my $self = bless {}, $class;
my $mw = MainWindow->new();
$self->{'mainwin'}=$mw;
$self->{'mycanvas'}=$mw->Canvas();
return $self;
}
sub getcanvas {
my $self=shift;
printf "Returning a %s\n",ref($self->{'mycanvas'});
return $self->{'mycanvas'}
}
package main;
my $YP = YourPackage->new();
my $canvas=$YP->getcanvas();
|