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

I have 2 text widgets (one is TextUndo and the other is ROText) and I want to map them together so that when the TextUndo (main text widget) scrolls the ROText widget scrolls with it. Is there any way to do that?

Replies are listed 'Best First'.
Re: map two text widgets using Tk?
by graff (Chancellor) on Jul 30, 2004 at 03:49 UTC
    Someone posted a similar question a few days ago -- I found it by going to Super Search and using "scroll two" as the search text. It may be that the first reply there has the answer to your question; if not, I'm pretty sure this question has come up before, so if you look further down the list returned by the search, you're bound to find something useful.
Re: map two text widgets using Tk?
by zentara (Cardinal) on Jul 30, 2004 at 17:25 UTC
    Here is a simplified example which ought to show you the basic idea. Doing tricks with scrollbars can get involved, so its best for you to jump in there and play with them.
    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Scrollbar; use Tk::Text; my $mw = Tk::MainWindow->new(); my $f1 = $mw->Frame()->pack(-side => 'top'); my $f2 = $mw->Frame()->pack(-side => 'left'); my $f3 = $mw->Frame()->pack(-side => 'bottom'); my $text1= $f1->Text( )->pack( -expand => 1, -fill => 'both', ); my $text2 = $f3->Text( )->pack( -expand => 1, -fill => 'both', ); # vertical scroll bar for both text windows my $yscroll = $f2->Scrollbar()->pack( -fill => 'y', -expand => 1, -side => 'right', ); $yscroll->configure( -command => [ \&scroll_both, $yscroll, [$text1,$t +ext2]]); $text1 ->configure( -yscrollcommand => [ \&set_yscroll ]); $text2 ->configure( -yscrollcommand => [ \&set_yscroll ]); &fill($text1); &fill($text2); MainLoop(); #------------------------------------------------------ sub fill{ my $widget = shift; for (1..300){ $widget->insert('end',"$_\n"); } $widget ->see('1.0'); $widget->idletasks; } #------------------------------------------------------- sub set_yscroll { # This handles updating yscroll, and making sure both the text # boxes are sync'ed when one of them scrolls via the cursor keys $yscroll->set(@_); foreach my $w ($text1, $text2) { $w->yviewMoveto($_[0]); } } #-------------------------------------------------------- sub scroll_both { my ($sb,$wigs,@args) = @_; my $w; foreach $w (@$wigs) { $w->yview(@args); } } #---------------------------------------------------------

    I'm not really a human, but I play one on earth. flash japh