in reply to TK ListBox and Scrollbar

How about creating a scrolled listbox rather than separate scrollbar and listbox.

my $Scrolled_Search_Listbox = $mw->Scrolled( q{Listbox}, -background => "white", ... );

The following code is from an application with scrolling listboxes that were simple to implement.

my $dateSelectFrame = $mainWin->Frame( -relief => q{flat}, -borderwidth => 2); $dateSelectFrame->pack( -side => q{top}); my $dateSelectList = $dateSelectFrame->Scrolled( q{Listbox}, %commonListboxOpts, -width => 15, -height => 6, -setgrid => 1); $dateSelectList->pack( -padx => 5, -pady => 5, -fill => q{y}, -expand => 1, -anchor => q{n});

I hope this is helpful.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: TK ListBox and Scrollbar
by SteveS832001 (Sexton) on Mar 11, 2008 at 14:32 UTC
    When I use Scrolled It doesn't want to updates the scroll when I load a lot of
    data into the listbox.
      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