Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: Question about embedded Tk::Canvas

by emilbarton (Scribe)
on Nov 20, 2013 at 19:13 UTC ( #1063578=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Question about embedded Tk::Canvas
in thread Question about embedded Tk::Canvas

The ancestors from the main window are:

$tracker_window = MainWindow->new.. $TrackBook = $tracker_window->NoteBook.. $TrackTabs{'Tracks'} = $TrackBook.. $Matrix = $TrackTabs{'Tracks'}->Scrolled.. $canvas = $Mainwin->Scrolled('Canvas')->grid.. my $real = $canvas->Subwidget("canvas"); # for bindings.. $CstObj->{'matrix'}->windowConfigure( "$i,1", -window => $canvas )..


Comment on Re^4: Question about embedded Tk::Canvas
Download Code
Re^5: Question about embedded Tk::Canvas
by kschwab (Priest) on Nov 20, 2013 at 19:31 UTC
    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();
      Ok, it seems quite a bit of a modification on my script. I don't understand why retrieving a reference aftewards should disturb but I'll apply this solution.

      Thank you very much for your help.
        Looking at your code on github, it's because of this:
        my $canvas = $Mainwin->Scrolled('Canvas')->grid; my $real = $canvas->Subwidget("canvas");
        Based on your choice of the variable name $real, you seem to already know what the issue is here :) $canvas isn't a 'Canvas'.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2015-07-06 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls