Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: TK Placing Widgets in a Scrolling Pane

by Anonymous Monk
on Dec 03, 2021 at 18:09 UTC ( [id://11139367]=note: print w/replies, xml ) Need Help??


in reply to TK Placing Widgets in a Scrolling Pane

You could use Tk:Pane and put multiple canvases where you want, and fill them as you want. Here is something to look at.
#!/usr/bin/perl use strict; use Tk; use Tk::Pane; my %frames; my %subframes; my %labels; my %buttons; my $mw = MainWindow->new; my $pane = $mw->Scrolled("Pane", -scrollbars => 'se', -sticky => 'nsew', -bg => 'black', -width => 300, -height => 300 )->pack(-expand => 1, -fill => 'both'); my $realpane = $pane->Subwidget('scrolled'); my $xbar = $pane->Subwidget('xscrollbar'); my $ybar = $pane->Subwidget('yscrollbar'); $ybar->configure(-background=>'blue', -activebackground=>'blue', -troughcolor => 'black', -width=> 50); $xbar->configure(-background=>'green', -activebackground=>'green', -troughcolor => 'black', -width=> 50); foreach my $row (0 .. 3) { $frames{$row} = $pane->Frame(-bg => 'black')->pack( -padx => 5, -pady => 5, -expand => 1, -fill => 'both', -anchor => 'nw', ); foreach my $col (0 .. 3) { createTile($row, $col); } } MainLoop; sub createTile { my ($row, $col) = @_; $subframes{$row}{$col}{'mainframe'} = $frames{$row}->Frame( -bg => 'black')->pack( -side => 'left', -padx => 5, -pady => 5, -expand => 1, -fill => 'both', -anchor => 'nw', ); my $frame = $subframes{$row}{$col}{'mainframe'}; my $sc = $frame->Scrolled('Canvas', -scrollbars => 'osoe', -scrollregion => [0, 0, 1200, 1200], -width => 125, -height => 125, -background => randColor() )->pack(-fill=>'both',-expand => 1, -side =>'top'); my $count = int(rand(6)) + 2; foreach my $i (1 .. $count) { my ($x, $y) = (randNumber(), randNumber()); my $size = randNumber(); $sc->createRectangle($x, $y, $x+$size, $y+$size, -fill => randColor(), -outline => 'black', -width => 2 ); } #miniframe for labels $subframes{$row}{$col}{'subframe_a'} = $frame->Frame( -bg => 'black')->pack(-side => 'top',-expand=> 1,-fill=>'bo +th'); #mini frame for buttons $subframes{$row}{$col}{'subframe_b'} = $frame->Frame( -bg => 'black')->pack(-side => 'top',-expand=> 1,-fill=>'bo +th'); #labels $labels{$row}{$col}{1} = $subframes{$row}{$col}{'subframe_a'}->Labe +l( -text => "$row - $col" , -bg => 'black', -fg => 'green', )->pack(-side => 'left', -padx => 5); $labels{$row}{$col}{2} = $subframes{$row}{$col}{'subframe_a'}->Label +( -text => "$row - $col" , -bg => 'black', -fg => 'hotpink', )->pack(-side => 'right', -padx => 5); #buttons $buttons{$row}{$col}{1} = $subframes{$row}{$col}{'subframe_b'}->Butt +on( -text => " Zoom Out ", -command => sub { $sc->scale(qw/all 0 0 .5 .5/); } )->pack(-side => 'left', -padx => 5); $buttons{$row}{$col}{2} = $subframes{$row}{$col}{'subframe_b'}->Butt +on( -text => " Zoom In", -command => sub { $sc->scale(qw/all 0 0 2 2/); } )->pack(-side => 'right', -padx => 5); } sub randColor { my @colors = qw(red yellow blue orange green purple); return $colors[rand($#colors + 1)]; } sub randNumber { my ($max, $min) = (100, 10); my $size = int(rand($max)); $size += $min if $size < $min; return $size; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-19 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found