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

Hi.

I've put together three listboxes with a common vertical scrollbar to the right of the third listbox using the TK library. I put an adjuster on the first and second listboxes. The issue I am having is that when either of the adjusters is used to stretch its listbox to the right then the widgets to the right of the adjuster slide off to the right out of view and are not displayed in the main window. Then when the adjuster is moved to the left to shrink the listbox then the widgets slide back into view in the main window. Do you know of a way to keep all of the widgets visible in the main window in this scenario, especially the vertical scrollbar such that it always stays "anchored" near the right edge of the main window.

I saw another post about keeping the size of widgets with adjusters in proportion to the size of the main window as the size of the main window changes but I am not sure if all of that is necessary to accomplish what I'm looking to do.

Thanks very much in advance. Tim

use Tk; use Tk::Adjuster; $mw = MainWindow->new(-title => "My Adjuster Example"); $mw->resizable( 0, 0 ); # not resizable in any direction $listboxesFrame = $mw->Frame(); $mfLbScrollBar = $listboxesFrame->Scrollbar(-orient=>'v'); $mfItemNameLb = $listboxesFrame->Listbox(-height => 25); $adj1 = $listboxesFrame->Adjuster(); $mfItemCurrentBubbleLb = $listboxesFrame->Listbox(-height => 25); $adj2 = $listboxesFrame->Adjuster(); $mfItemOtherBubbleLb = $listboxesFrame->Listbox(-height => 25); # Array of the three Listboxes $mfListBoxes = [ $mfItemNameLb, $mfItemCurrentBubbleLb, $mfItemOtherBu +bbleLb ]; # Configure each Listbox to call &scroll_listboxes foreach $list (@$mfListBoxes) { $list->configure(-yscrollcommand => [ \&scroll_listboxes, $mfLbScrol +lBar, $list, $mfListBoxes ]); } # Configure the Scrollbar to scroll each Listbox $mfLbScrollBar->configure(-command => sub { foreach $list (@$mfListBox +es) { $list->yview(@_); }}); $mfItemNameLb->pack(-side => 'left', -expand => 1, -fill => 'both'); $adj1->packAfter($mfItemNameLb, -side => 'left'); $mfItemCurrentBubbleLb->pack(-side => 'left', -expand => 1, -fill => ' +both'); $adj2->packAfter($mfItemCurrentBubbleLb, -side => 'left'); $mfItemOtherBubbleLb->pack(-side => 'left', -expand => 1, -fill => 'bo +th'); $mfLbScrollBar->pack(-side => 'right', -fill => 'y'); $listboxesFrame->grid(-row=>1,-column=>1, -padx => 10, -pady => 10); MainLoop; sub scroll_listboxes { my ($sb, $scrolled, $lbs, @args) = @_; $sb->set(@args); # tell the Scrollbar what to display my ($top, $bottom) = $scrolled->yview( ); foreach $list (@$lbs) { $list->yviewMoveto($top); # adjust each lb } }

  • Comment on Tk::Adjuster causes widgets to slide out of the main window out of view
  • Download Code

Replies are listed 'Best First'.
Re: Tk::Adjuster causes widgets to slide out of the main window out of view
by lamprecht (Friar) on Jan 07, 2011 at 15:57 UTC
    Hi Tim,

    keep the scrollbar outside of the frame that holds the adjusted widgets:


    Cheers, Chris

      Chris, that change made it work exactly how I wanted it to work. Thanks for the timely help!!!

      Tim