Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^5: Question about embedded Tk::Canvas

by kschwab (Priest)
on Nov 20, 2013 at 19:31 UTC ( #1063582=note: print w/replies, xml ) Need Help??

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

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 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();

Replies are listed 'Best First'.
Re^6: Question about embedded Tk::Canvas
by emilbarton (Scribe) on Nov 20, 2013 at 19:39 UTC
    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'.
        Hey, I always wondered was real meant in this way.. I think I just copied from TextUndo tricks I had to use somewhere else. Maybe it's not of any use here.
        No I'm sorry, removing this workaround doesn't change anything, and I'll have to try your first proposal... In the meantime I found where this comes from: I had experienced key-binding problems in Scrolled TextUndo widgets and could apply with success Zentara's tip given here Re^3: Tk hidden binding, so to be on the safe side, as my canvas is scrolled too, I just applied the same here in prevision of possible key-bindings and problems. Anyway, I must acknowledge I often copy and paste bits of code without always being sure they're appropriate, when it works no further verification is made (shame on me!).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-09-23 13:49 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (191 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!