in reply to Invoking scrolling externally on a Perl/Tk Scrolled widget

It is much simpler than this. The see() method of Listbox allows you to scroll a particular list element into the "view".

use strict; use Tk; my $main = MainWindow->new; my $list = $main->Scrolled('Listbox', -scrollbars => 'e', -selectmode => 'single')->pack; foreach my $i (1..100) { $list->insert('end', "item $i"); } my $button = $main->Button(-text => "Scroll to Bottom of List", -command => \&scroll_to_bottom)->pack; MainLoop; sub scroll_to_bottom { $list->see('end');#make the last element viewable }

Replies are listed 'Best First'.
Re: Re: Invoking scrolling externally on a Perl/Tk Scrolled widget
by forrest (Beadle) on Nov 30, 2003 at 17:10 UTC
    Oh, that's cool.

    I found another solution: if I replace

    $list->Subwidget("yscrollbar")->set($first, $last);
    with
    $list->yviewMoveto($first);
    it works.
      Hey, I am glad to see I am not the only one who is interested in achieving this. However I want to be able to scroll to a certain line number and have the cursor be flashing at the beginning of the line I want to scroll to. I am using Text instead of ListBox though. Anyone have any ideas?
        I think the yviewMoveto method will work to get your widget where you want it; my understanding is it works on any Scrolled widget. (In my real project I needed to scroll a TableMatrix, but I didn't want to post a complex example here.)

        You just need to pass the value of ($line_to_scroll_to/$total_lines) to the method.

        Flashing I don't know about, though.