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

use strict; use warnings; use Tk; use Tk::Scrollbar; use Tk::Text; our ($textL, $textR, $yscroll, $xscrollleft, $xscrollright); my $main = Tk::MainWindow->new(); my $topframe = $main->Frame()->pack(); my $topleftframe = $topframe->Frame()->pack(-side => 'left'); my $toprightframe = $topframe->Frame()->pack(-side => 'left'); # Left again, because the yscroll is actually going on the right # and putting right here would put yscroll in the middle # Create left Text widget... $textL= $topleftframe->Text(-wrap => 'none' )->pack( -expand => 1, -fill => 'both', ); # Create right Text Widget... $textR = $toprightframe->Text(-width=>'20', -wrap => 'none' )->pack( -expand => 1, -fill => 'both', ); #################################### # scrollbars #################################### # Setup vertical scroll bar for both text windows $yscroll = $topframe->Scrollbar()->pack( -fill => 'y', -side => 'right', ); # Setup two individual horizontal scroll bars for the text windows $xscrollleft = $topleftframe->Scrollbar( -orient=>'horizontal', )->pack( -fill => 'x', -side => 'bottom', -expand => 1, ); $xscrollright = $toprightframe->Scrollbar( -orient=>'horizontal', )->pack( -fill => 'x', -side => 'bottom', -expand => 1, ); # Connect scrollbars to text widgets (and back again)... $xscrollright ->configure( -command => [ \&xscroll_right, $xscrollright, $te +xtR]); $xscrollleft ->configure( -command => [ \&xscroll_left, $xscrollleft, $te +xtL]); $yscroll->configure( -command => [ \&scroll_both, $yscroll, [$te +xtL, $te +xtR]]); $textL ->configure( -yscrollcommand => [ \&set_yscroll ]); $textR ->configure( -yscrollcommand => [ \&set_yscroll ]); $textL ->configure( -xscrollcommand => [ 'set', $xscrollleft]); $textR ->configure( -xscrollcommand => [ 'set', $xscrollright]); # Load some data into them (FOR TESTING ONLY) insert_data(); MainLoop(); # This handles updating yscroll, and making sure both the text # boxes are sync'ed when one of them scrolls via the cursor keys sub set_yscroll { $yscroll->set(@_); foreach my $w ($textL, $textR) { $w->yviewMoveto($_[0]); } } sub scroll_both { my ($sb,$wigs,@args) = @_; my $w; foreach $w (@$wigs) { $w->yview(@args); } } sub xscroll_right { my ($sb,$w,@args) = @_; $w->xview(@args); } sub xscroll_left { my ($sb,$w,@args) = @_; $w->xview(@args); } sub insert_data { my $testdata = <<'EOTESTDATA'; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 + 27 28 29 30 31 32 33 34 35 36 37 38 39 Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 + 27 28 29 30 31 32 33 34 35 36 37 38 39 Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 + 27 28 29 30 31 32 33 34 35 36 37 38 39 EOTESTDATA $textL->insert('end', $testdata); $textR->insert('end', $testdata); }

bbfu
Black flowers blossum
Fearless on my breath


In reply to (bbfu) Re: Tricky Perl Tk scrollbars by bbfu
in thread Tricky Perl Tk scrollbars by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.