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

Trying to debug my script, I broke it down to bare minimum:
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Pane; my $mw = MainWindow->new( ); $mw->minsize(200,300); my $pane = $mw->Scrolled( 'Pane', -scrollbars => 'e', -border => 2, )->pack(-fill=>'both', -expand=>1); foreach my $x (1..100) { my $label = $pane->Label( -text => $x, )->pack(-side=>'top', -fill=>'x', -expand=>0); # $pane->yview(moveto => 1); } MainLoop;

Above script suppose to create a Pane, then populate it with 100 labels.
So far so good.


Uncommenting the line $pane->yview($label);, it is suppose to scroll to the bottom.
But I get this error:

Can't call method "Call" on an undefined value at C:/Perl/site/lib/Tk/Pane.pm line 346.

What is wrong?

According to documents (http://search.cpan.org/~srezic/Tk/Tk/Pane.pm):
$pane->yview(moveto => 1) Is how to scroll to the very bottom but it is not doing so. Why?

Replies are listed 'Best First'.
Re: TK Pane->yview not working?
by tybalt89 (Monsignor) on Apr 22, 2018 at 20:39 UTC

    moveto => 1 works if you do it after the geometry manager has run, which seems to be the trick for both of your problems.

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1213368 use strict; use warnings; use Tk; use Tk::Pane; my $mw = MainWindow->new( ); $mw->minsize(200,300); my $pane = $mw->Scrolled( 'Pane', -scrollbars => 'e', -border => 2, )->pack(-fill=>'both', -expand=>1); foreach my $x (1..100) { my $label = $pane->Label( -text => $x, )->pack(-side=>'top', -fill=>'x', -expand=>0); } $mw->after(1, sub { $pane->yview(moveto => 1) } ); MainLoop;
Re: TK Pane->yview not working?
by tybalt89 (Monsignor) on Apr 22, 2018 at 14:30 UTC
    #!/usr/bin/perl # http://perlmonks.org/?node_id=1213368 use strict; use warnings; use Tk; use Tk::Pane; my $mw = MainWindow->new( ); $mw->minsize(200,300); my $pane = $mw->Scrolled( 'Pane', -scrollbars => 'e', -border => 2, )->pack(-fill=>'both', -expand=>1); foreach my $x (1..100) { my $label = $pane->Label( -text => $x, )->pack(-side=>'top', -fill=>'x', -expand=>0); $mw->update; $pane->yview($label); } MainLoop;