textarea - How can I create 2 Perl/TK text areas with scrollbars that when I scroll one both text areas scroll at the same time? -
is possible using tk create text areas scrollbars when scroll 1 other moves well?
what want create text area headers in , text areas underneath row headings in 1 , data in other. kind of when freeze panes in excel. have data in set of arrays each line, need way of linking scrollbars in each of text areas down 1 in data controls row headings , vice versa, , left right 1 of data controls column headings , again vice versa.
probably not possible doesn't hurt ask
edit
ok have got code , want need getting work completely. code example shows if move 1 scrollbar indeed controls other text area, , vice versa, doesnt control own text area, there way of adding multiple xviews command moves both textareas @ same time. in advance
use tk; use tk::rotext; @headers = ( "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+", "| | m | m | m | m | m | m | m | m | m | m | m | m | m | m |", "| | p | p | p | p | p | p | p | p | p | p | p | p | p | p |", "| | l | l | l | l | l | l | l | l | l | l | l | l | l | l |", "| | r | r | r | r | r | r | r | r | r | r | r | r | r | r |", "| | d | d | d | d | d | d | d | d | d | d | d | d | d | d |", "| | f | f | f | f | f | f | f | f | f | f | f | f | f | f |", "| | d | d | d | d | d | d | d | d | d | d | d | d | d | d |", "| | s | s | s | s | s | e | e | e | e | e | e | b | b | b |", "| | o | o | o | o | o | v | v | v | v | v | v | | | |", "| | | | | | | f | f | f | f | f | f | q | q | q |", "| | k | k | k | k | k | b | c | f | g | h | | | | |", "| | 1 | 5 | 6 | 7 | 8 | | | | | | | 1 | 2 | 3 |"); @info = ( "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+", "| lhadhrdt | | | | | | | | | | | | | | 1|", "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+", "| lhbaerdt | | 4| | 4| | | | | | | | | | |", "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+", "| lhee1rdt | | | 13| | | | | | 48| | | | | |", "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+", "| lhlm2rdt | 96| | | | | | | | | | | | | |", "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+", "| lhlserdt | | | | | | | | | | | | | 7| |", "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+", "| lhlw1rdt | | | | | | | | | | | 9304| | | |", "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+", "| lhup1rdt | | | | | 160|84385| | | | 271| | | | |", "+----------------+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+"); $mw = mainwindow->new ( -background => "grey" ); $mw->title("what gap issues there have been"); $mw->resizable(0, 0); $mw->focus; $mw->geometry("600x400"); $ta1f = $mw->frame(-width=>5,-height=>5,-foreground=>"blue",-background=>"grey",-borderwidth=>2,-relief=>'groove')->place(-x=>5,-y=>5); $ta1 = $ta1f->scrolled( 'rotext', -scrollbars => 'se', -height => 10)->pack(-side => 'left'); $ta1->configure(-background => "grey",-wrap=>"none"); $ta1->insert('end', "$_\n") foreach @headers; $ta2f = $mw->frame(-width=>5,-height=>5,-foreground=>"blue",-background=>"grey",-borderwidth=>2,-relief=>'groove')->place(-x=>5,-y=>200); $ta2 = $ta2f->scrolled( 'rotext', -scrollbars => 'se', -height => 10)->pack(-side => 'left'); $ta2->configure(-background => "grey",-wrap=>"none"); $ta2->insert('end', "$_\n") foreach @info; $ta1->subwidget("xscrollbar")->configure(-command => ['xview', $ta2]); $ta2->subwidget("xscrollbar")->configure(-command => ['xview', $ta1]); $mw->focus; mainloop; exit 0;
it's possible. use scrollbar's -command
option invoke procedure. in procedure, call yview
on each text area want move.
update
when wrote original answer, didn't read enough see using perl/tk -- assumed tcl/tk. nevertheless, same principle applies.
the following code replaces have below first $mw->focus;
-- uses single horizontal scrollbar control 2 text widgets.
my $horiz = $mw->scrollbar(-orient => 'horizontal'); $f1 = $mw->frame(); $vert1 = $f1->scrollbar(); $text1 = $f1->rotext( -height => 10, -wrap => 'none', -yscrollcommand => [set => $vert1], -xscrollcommand => [set => $horiz], ); $text1->insert('end', "$_\n") foreach @headers; $text1->pack(-side => 'left'); $vert1->configure(-command => [yview => $text1]); $vert1->pack(-side => 'left', -fill => 'y', -expand => 1); $f2 = $mw->frame(); $vert2 = $f2->scrollbar(); $text2 = $f2->rotext( -height => 10, -wrap => 'none', -yscrollcommand => [set => $vert2], -xscrollcommand => [set => $horiz], ); $text2->insert('end', "$_\n") foreach @info; $text2->pack(-side => 'left'); $vert2->configure(-command => [yview => $text2]); $vert2->pack(-side => 'left', -fill => 'y', -expand => 1); $horiz->configure(-command => sub { $text1->xview(@_); $text2->xview(@_) }); $f1->pack; $f2->pack; $horiz->pack(-fill => 'x', -expand => 1); mainloop; exit 0;
Comments
Post a Comment