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

Dear monks,
I am writing a GUI for a program. This GUI has two text boxes
($text and $text2) a vertical scrollbar that scrolls both
textboxes and two horizontal scrollbars that are meant to scroll
each textbox (separately) horizontally. I am not using scrolled,
so that I can get my vertical scrollbar moving both boxes.
The two textboxes and the vertical scrollbar and in $topframe
and the horizontals are in $middleframe, below the textboxes.
The problem is the horizontal bars are teeny-weeny not filling up the
x axis despite me using fill=>'x'
The vertical scroll is fine, any ideas on why my horizontals arent working ?
Here is the code:
#################################### # scrollbars #################################### # Setup two individual horizontal scroll bars for the text windows # Setup vertical scroll bar for both text windows $yscroll= $topframe->Scrollbar()->pack(-fill => 'y', -side => 'right') +; sub scroll_both{ my ($sb,$wigs,@args) = @_; my $w; foreach $w (@$wigs) { $w->yview(@args); } } # Create Right Text widget... my $text = $topframe->Text(-wrap => 'none' )-> pack(-expand=> 1, -fill=> 'both', -side=> 'right'); # Create Left Text Widget... my $text2 = $topframe->Text(-width=>'20', -wrap => 'none' )-> pack(-expand=> 1, -fill=> 'both'); $xscrollleft= $middleframe->Scrollbar(-orient=>'horizontal')->pack(-fi +ll => 'x',-side=>'left',-expand=> 1,); $xscrollright= $middleframe->Scrollbar(-orient=>'horizontal')->pack(-f +ill => 'x',-side=>'right',-expand=> 1,); # Connect scrollbars to text widgets... $yscroll->configure( -command => [ \&scroll_both, $yscroll, [$text,$text2]]); $text->configure( -yscrollcommand => [ 'set', $yscroll]); $text2->configure( -yscrollcommand => [ 'set', $yscroll]); $text2->configure( -xscrollcommand => [ 'set', $xscrollright]); $text->configure( -xscrollcommand => [ 'set', $xscrollleft]);

Thanks for your time

Replies are listed 'Best First'.
(bbfu) Re: Tricky Perl Tk scrollbars
by bbfu (Curate) on Nov 23, 2002 at 23:37 UTC

    A few things...

    First, your left/right text/text2 was a little confusing, so I'm not sure if I got the right (er, correct) ones on the correct sides. It should be pretty straight-forward to fix if not, though.

    Second, you didn't include enough of the surrounding code to make this runnable, so I had to create my own. I think the problem you asked about is actually in the code you did not include (ie, $middleframe is not pack()'ed to fill horizontally and the scrollbars were just filling $middleframe but not the whole window) but it became moot (see below).

    Third, even if you'd gotten the horizontal scrollbars to fill out horizontally, the separation between them wouldn't have lined up with the separation between the text boxes. What you need to do is make a frame for each text box, which includes the text box on the top and the horizontal scrollbar on the bottom. $middleframe is not needed.

    (The rest are actually unrelated to your question but I assume you will want them corrected later, if they're not already by code you didn't include.)

    Fourth, you didn't have a -command set for either of the horizontal scrollbars. Thus, while they updated themselves properly when the text box was scrolled via the cursor keys, you couldn't scroll the text box by clicking on them.

    And lastly, scrolling one text box via cursor keys updated the scrollbar but didn't scroll the other text box.

    Anyway, below is the code I managed to get working the way (I assume) you wanted. All of the above issues should be addressed. :) Of course, you will want to ignore the setup and data sections, as they will be taken care of by your other code. I rearranged several of the sections, and changed the formatting a bit, renamed a few of the variables, and changed the scope on a few, to make it easier for me to follow the code. Change it back as you see fit. :D

    bbfu
    Black flowers blossum
    Fearless on my breath