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

I created a scrolled list box but when I populate it with more entries than can be displayed (more than 5 entries), the scroll bar is greyed out - not allowing me to scroll. Resizing the window after it's populated activates the scroll bar, as does a separate function that fills that box. I'm running on a Windows XP machine. Hopefully this is all the relevent code needed to determine the problem.

my $frm1 = $mw -> Frame(-bg=>'LightSkyBlue1') -> pack(-fill => 'x'); my $frm11 = $frm1 -> Frame(-bg=>'LightSkyBlue1') -> pack(-fill => 'x') +; my $lst = $frm11 -> Scrolled('Listbox', -width => 50, -height => 5, -scrollbars => 'oe', -selectmode => 'single') -> pack(); (generate @lst_files) $lst -> delete ('0.0', 'end'); $lst -> insert('end', @lst_files); $mw->update;

Replies are listed 'Best First'.
Re: Inactive Scroll Bar - Scrolled Listbox
by zentara (Cardinal) on Apr 12, 2011 at 16:26 UTC
    I don't see your problem, but you are not showing a complete running example. How does this run for you?
    #!/usr/bin/perl -w 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 { my ($first, $last) = $list->Subwidget("yscrollbar")->get; print "Listbox window is from $first to $last\n"; # set to end of list my $winsize = $last - $first; $first = 1.0 - $winsize; $last = 1.0; $list->Subwidget("yscrollbar")->set($first, $last); $list->see('end'); #scroll all the way down #$list->see('55'); #scroll to some index print "Set listbox window from $first to $last\n"; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      The code you posted works fine. What part is of my code would you like to see? It's a very large script so I tried to pull the parts related to the scroll bar.

        Here is a complete runnable example, that demonstrates the problem:

        use strict; use warnings; use Tk; my $mw = tkinit; my $frm1 = $mw -> Frame(-bg=>'LightSkyBlue1') -> pack(-fill => 'x'); my $frm11 = $frm1 -> Frame(-bg=>'LightSkyBlue1') -> pack(-fill => 'x') +; my $lst = $frm11 -> Scrolled('Listbox', -width => 50, -height => 5, -scrollbars => 'oe', -selectmode => 'single') -> pack(); $mw->update; $lst -> delete ('0.0', 'end'); $lst -> insert('end',(0..10)); $mw->update; # force scrollbar refresh: # my $sb = $lst->Subwidget('yscrollbar'); # $sb->set( $sb->get ); MainLoop;
        See also:
        Re: Perl/Tk Optional Vertical Scrollbar Bugfix

        Cheers, Christoph