Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Tk:: How to do a pane which scrolls partially

by tcarmeli (Beadle)
on Nov 15, 2006 at 15:55 UTC ( [id://584188]=perlquestion: print w/replies, xml ) Need Help??

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

Hi,
I'm trying to implement something similar to Excell's "Freeze Panes" functionality.
I would like to have a table when only the cells scroll and the headings stay on top.
See the attached code for an example. I would like the '0' and '1' headings to stay on top.
A possible solution is to put two frames one on top of the other, when only the lower is scrollable. This works but you loose the strength of the "grid" geometry manager, and you need to take care of the sizes so the columns align all right.
Thanks!
use strict; use Tk; use Tk::Pane; my $sc; my $x; my $i; my $j; my $box; my $mw = MainWindow->new; my $frame = $mw->Scrolled("Frame", -scrollbars => 'osoe', -sticky => 'nsew', -bg => 'black', -width => 900, -height => 500 )->pack(qw/-expand 1 -fill both/); foreach $i (0 .. 1) { $frame->Label( -text => $i, -relief => 'groove', -font => "{Arial} 15 bold", -borderwidth => 2, )->grid( -row => 0, -sticky=>"nsew", -column => $i, ); foreach $j (1 .. 4) { $sc = $frame->Canvas( -width => 400, -height => 125, -background => randColor() )->grid( -row => $j, -sticky => "nsew", -column => $i, ); $x = randNumber(); $box = $sc->createRectangle($x, 50, $x+20, 90, -fill => randColor(), -outline => 'black', -width => 2, -tags => 'rect', ); $sc->createLine( 10,100, 790,100, -arrow => 'last'); for($x=50;$x<800;$x+=50){ $sc->createLine( $x,95, $x,105 ); } } } MainLoop; sub randColor { my @colors = qw(red yellow blue orange green purple cyan pink); return $colors[rand($#colors + 1)]; } sub randNumber { my ($max, $min) = (350, 50); my $size = int(rand($max)); $size += $min if $size < $min; return $size; }

Replies are listed 'Best First'.
Re: Tk:: How to do a pane which scrolls partially
by zentara (Archbishop) on Nov 15, 2006 at 16:15 UTC
    I don't know whether it's worth the effort trying to grid such a complicated interaction. Here is a similar idea, on how to match up and link-scroll on a few canvases. Notice that by packing(instead of griding), it will auto-resize nicely.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow(); $mw->geometry("600x400+200+200"); my $topframe = $mw->Frame(-bg=>'grey65')->pack(); my $infolab = $topframe->Label(-text =>'Some Info')->pack(); my $midframe = $mw->Frame(-bg=>'grey85')->pack(); my $midframel = $midframe->Frame(-bg=>'grey85')->pack(-side=>'left',-e +xpand=>1,-fill=>'y'); my $midframer = $midframe->Frame(-bg=>'grey85')->pack(-side=>'right'); my $botframe = $mw->Frame(-bg=>'grey85')->pack(); my $canvast = $midframer->Canvas( -bg =>'lightyellow', -width=>24000, -height=>25, -scrollregion=>[0,0,25000,1000], -xscrollincrement => 1, ) ->pack(-side=>'top'); my $canvasp = $midframer->Scrolled('Canvas', -bg =>'lightseagreen', -width=>24000, -height=>1000, -scrollregion=>[0,0,25000,1000], -scrollbars=>'se', #use the xscrollcommand in the subwidget instead # -xscrollcommand => \&xscrollit, -xscrollincrement => 1, -yscrollincrement => 1, ) ->pack(-side=>'bottom',-fill=>'both'); my $canvass = $midframel->Canvas( -bg =>'lightsteelblue', -width=>50, -height=>1000, -scrollregion=>[0,0,50,1000], -yscrollincrement => 1, ) ->pack(-side=>'top',-fill=>'both'); my $xscroll = $canvasp->Subwidget("xscrollbar"); my $yscroll = $canvasp->Subwidget("yscrollbar"); $xscroll->configure(-troughcolor =>'white', -activebackground =>'black', -command => \&xscrollit, ); $yscroll->configure(-troughcolor =>'white', -activebackground =>'black', -command => \&yscrollit, ); #create timebar and markers for(0..24000){ if( $_ % 100 == 0){ $canvast->createLine($_,0,$_,10); $canvast->createText($_,20,-text=>$_); next; } } for(0..24000){ if( $_ % 100 == 0){ $canvasp->createLine($_,0,$_,10); $canvasp->createText($_,20,-text=>$_); next; } } #create station boxes for(0..50){ $canvass->createRectangle(0,25+ $_*50, 50, 75 + $_*50, -fill =>'hotpink', ); } MainLoop; ###################################################################### +# sub xscrollit{ my $fraction = $_[1]; print "$fraction\n"; $canvast->xviewMoveto($fraction); $canvasp->xviewMoveto($fraction); } ###################################################################### sub yscrollit{ my $fraction = $_[1]; print "$fraction\n"; $canvass->yviewMoveto($fraction); $canvasp->yviewMoveto($fraction); } ######################################################################

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Tk:: How to do a pane which scrolls partially
by mikasue (Friar) on Nov 16, 2006 at 14:25 UTC
      Thanks,
      Seems there are some problems with getting it to work on a PC, however Tk::Table seems to work well for that too

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://584188]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-25 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found