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

Dear Monks, I wonder if it's possible to create a scrolled widget via the method scrolled, and to let the position of the vertical scrollbar be on the bottom by default. This should look similar to a dos command promt.
#!/usr/bin/perl -w use Tk; use Tk::Pane; $mw=MainWindow->new(); $mw->geometry("100x100"); $mw->Button(-text=>"START",-command=>\&start_computation)->pack; MainLoop; sub start_computation { $progress=$mw->Toplevel(); $progress->geometry("200x100"); $pane=$progress->Scrolled('Pane',-scrollbars=>'oe')->pack(-fill=>' +both',-expand=>1); $text="Computation started...\n"; $label=$pane->Label(-text=>$text)->pack(); # doing several computation steps foreach$step(1..10) { sleep(1); $text.="Step $step finished.\n"; $label->configure(-text=>$text); $pane->update; } $text.="\nComputation finished.\n"; $label->configure(-text=>$text); $pane->update; $pane->Button(-text=>"QUIT",-command=>sub{exit;})->pack; }

Replies are listed 'Best First'.
Re: Perl::Tk Vertical scrollbar on the bottom by default?
by kcott (Archbishop) on Dec 02, 2010 at 11:54 UTC

    I'm assuming you want the slider of the vertical scrollbar to always be at the bottom, rather than the scrollbar itself to be on the bottom. If that is the case, use the -yscrollcommand option (see Tk::options).

    See also Tk::Scrolled, Tk::Scrollbar and the documentation for the widget to be so affected (it might have special or non-standard scrolling behaviour).

    -- Ken

Re: Perl::Tk Vertical scrollbar on the bottom by default?
by Tux (Canon) on Dec 02, 2010 at 12:16 UTC

    You need the yview method, but that fails if there is nothing to be scrolled (if everything already fits), so you need some protection:

    use strict; use warnings; use Tk; use Tk::Pane; my $mw = MainWindow->new (); $mw->geometry ("100x100"); $mw->Button (-text => "START", -command => \&start_computation)->pack; MainLoop; sub start_computation { my $progress = $mw->Toplevel (); my $sp = $progress->Scrolled ("Pane", Name => "Progress", -width => 200, -height => 100, -scrollbars => "ose", )->pack (-anchor => "nw", -fill => "both", -expand => 1); my $text = "Computation started...\n"; my $label = $sp->Label (-text => $text)->pack (); # doing several computation steps foreach my $step (1 .. 10) { sleep (1); $text .= "Step $step finished.\n"; $label->configure (-text => $text); my @pos = $sp->yview; $pos[1] < 1 and $sp->yview (moveto => 1.); $sp->update; } $text .= "\nComputation finished.\n"; $label->configure (-text => $text); $sp->yview (moveto => 1); $sp->update; $sp->Button (-text => "QUIT", -command => sub { exit; })->pack; } # start_computation

    Enjoy, Have FUN! H.Merijn