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

Hello,

I would like to have on the same Window a Canvas widget and a Scale widget, but I have the error below :

Tk::Error: bad window path name "all" at ./test.pl line 22. Tk callback for scale Tk::After::repeat at /usr/lib/perl5/vendor_perl/5.22/i686-cygwin-thre +ads-64int/Tk/After.pm line 80 [repeat,[{},after#13,500,repeat,[\&main::__ANON__]]] ("after" script)

This the example with the problem:

#!/usr/bin/perl use warnings; use Tk; sub GUI() { $fenetre = new MainWindow( -title => 'test', ); $fenetre->minsize( 200, 70 ); $cadre_voie = $fenetre->Frame()->pack(-fill => 'both', -expand => +1); $voie = $cadre_voie->Scrolled( 'Canvas', -background => '#A0A0A0', ); $voie->pack(-fill => 'both', -expand => 1); $cadre_voie->Scale(-orient=>'horizontal')-> pack(); $fenetre->repeat( 500, sub { $voie->scale('all',0,0,1,1); } ); MainLoop; # Obligatoire } GUI();

Do you have a solution to fix this problem ? or to explain me the problem ?

Thanks, Regards.

Replies are listed 'Best First'.
Re: Tk::Error: bad window path name "all"
by Anonymous Monk on Nov 04, 2015 at 23:07 UTC

    A Scrolled object is not the real thing, it's the parent of the real thing. Mostly, things work properly, but not always.

    Get the real canvas and apply ->scale to that:

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1146938 use strict; use warnings; use Tk; sub GUI() { my $fenetre = new MainWindow( -title => 'test', ); $fenetre->minsize( 200, 70 ); my $cadre_voie = $fenetre->Frame()->pack(-fill => 'both', -expand +=> 1); my $voie = $cadre_voie->Scrolled( 'Canvas', -background => '#A0A0A0', ); $voie->pack(-fill => 'both', -expand => 1); my $realcanvas = $voie->{SubWidget}{canvas}; $cadre_voie->Scale(-orient=>'horizontal')-> pack(); #$fenetre->repeat( 500, sub { $voie->scale('all',0,0,1,1); } ); $fenetre->repeat( 500, sub { $realcanvas->scale('all',0,0,1,1); } +); MainLoop; # Obligatoire } GUI();

      See Tk::Scrolled it provides an accessor

      $ perl -MTk -le " $mw=tkinit; $s = $mw->Scrolled(q/Canvas/); print $s; + print $s->Subwidget(q/scrolled/); " Tk::Frame=HASH(0xf35ba4) Tk::Canvas=HASH(0xf14b54)