in reply to Re^2: TK ListBox and Scrollbar
in thread TK ListBox and Scrollbar

I've knocked up this little app. which inserts ten items into the listbox every time you hit the <Insert> button. It seems to update the scroll bar ok on my system, Sun Ultra 30, Solaris 9, perl 5.8.4, Tk-804.027.

use strict; use warnings; use Tk; my $rcGetTen = do { my $count = 0; sub { my @arr; push @arr, q{Item } . ++ $count for 1 .. 10; return @arr; }; }; my $bgColour = q{LightSteelBlue3}; my %labelColours = ( -foreground => q{NavyBlue}, -background => q{LemonChiffon} ); my %buttonColours = ( -background => q{grey35}, -foreground => q{yellow2}, -activebackground => q{grey45}, -activeforeground => q{yellow}, -disabledforeground => q{grey55} ); my %commonListboxOpts = ( -setgrid => 1, -scrollbars => q{e}, -selectmode => q{single}, -selectforeground => q{grey35}, -selectbackground => q{AntiqueWhite}, -exportselection => 0 ); my $mainWin = MainWindow->new( -background => $bgColour, ); $mainWin->title(q{scrollListbox}); my $listboxFrame = $mainWin->Frame( -relief => q{flat}, -background => $bgColour, -borderwidth => 2, ); $listboxFrame->pack( -side => q{top}, ); my $listbox = $listboxFrame->Scrolled( q{Listbox}, %commonListboxOpts, -width => 15, -height => 6, -setgrid => 1, ); $listbox->pack( -padx => 5, -pady => 5, -fill => q{y}, -expand => 1, -anchor => q{n}, ); my $controlButtonFrame = $mainWin->Frame( -relief => q{flat}, -background => $bgColour, -borderwidth => 2, ); $controlButtonFrame->pack( -side => q{top}, ); my $quitButton = $controlButtonFrame->Button( %buttonColours, -width => 6, -text => q{Quit}, -command => sub {exit;}, ); $quitButton->pack( -side => q{right}, -padx => 5, -pady => 5, ); my $insertButton = $controlButtonFrame->Button( %buttonColours, -width => 6, -text => q{Insert}, -command => sub { $listbox->insert( q{end}, $rcGetTen->() ) }, ); $insertButton->pack( -side => q{right}, -padx => 5, -pady => 5, ); MainLoop();

I hope this is of interest.

Cheers,

JohnGG