MountainDon't has asked for the wisdom of the Perl Monks concerning the following question:

Hi there! I am trying to set up some panes within frames within panes etc. just to test my knowledge of Tk panes and frames, and I have run into something I can't figure out.

I want an pane with a scrollbar on the bottom. In this pane, I want a blue bar (a frame with blue background) that's 40p tall and 500p wide that sticks to the top of pane. Underneath that blue bar, still in the first pane, I want another pane with a scrollbar on the right side. And in that pane, I want a green bar (frame with green background) that's 40p wide and 500p tall that sticks to the left of its parent frame.

I hope that's clear enough haha. Anyway, with what I've got below, all I'm seeing is the outer pane with the scrollbar at the bottom and the blue bar (which is not on the top of the pane :/ ) and no sign of the inside pane or green bar. Please shed some wisdom on me, where are my widgets?!

Also any other side notes on my code are gladly accepted!

use warnings; use Tk; use Tk::Pane; $mw = new MainWindow; $mw -> geometry("500x500"); $outerPane = $mw -> Scrolled("Pane", -scrollbars => 's') -> pack(-fill + => "both", -expand => 1); $blueBar = $outerPane -> Frame(-background => "light blue", -height => + 40, -width => 500) -> pack(); $innerPane = $outerPane -> Scrolled("Pane", -scrollbars => 'w') -> pac +k(-fill => "both", -expand => 1); $greenBar = $innerPane -> Frame(-background => "light green", -width = +> 40, -height => 500) -> pack(-fill => "y"); MainLoop();

Replies are listed 'Best First'.
Re: Perl Tk Panes/Frames (probably simple)
by thundergnat (Deacon) on Sep 11, 2015 at 13:38 UTC

    You probably should consider reading the documentation for Tk::Pane. If you want a Pane to "stick" to the edges of a container, you need to specify the -sticky option.

    What it sounds like you are trying to do based on your description: (strict clean and perltidy-ed)

    use warnings; use strict; use Tk; use Tk::Pane; my $mw = new MainWindow; $mw->geometry('500x500'); my $outerPane = $mw->Scrolled( 'Pane', -scrollbars => 's', -sticky => 'nsew' ) ->pack( -fill => 'both', -expand => 1 ); my $blueBar = $outerPane->Frame( -background => 'light blue', -height => 40, -width => 500 )->pack( -fill => 'x', -side => 'top' ); my $innerPane = $outerPane->Scrolled( 'Pane', -scrollbars => 'w', -sticky => 'nsew' )->pack( -fill => 'both', -expand => 1 ); my $greenBar = $innerPane->Frame( -background => 'light green', -width => 40, -height => 500 )->pack( -fill => 'y', -side => 'left' ); MainLoop;
      Ahhhh. Yes, I definitely should read that. I'm indebted to you my friend!
Re: Perl Tk Panes/Frames (sub Tk::Widget::Scrolled and sub Tk::Frame::AddScrollbars )
by Anonymous Monk on Sep 10, 2015 at 22:35 UTC

    (probably simple) ... and no sign of the inside pane or green bar. Please shed some wisdom on me, where are my widgets?!

    :) it never is

    When trying to figure stuff like this out, add -bg to every widget

    Also add a label or other widgets like Re: TK Gui Help

    See Tk::pack for description of the algorithm

    Use Tk::WidgetDump to see what p> See sub Tk::Widget::Scrolled and sub Tk::Frame::AddScrollbars actually does

Re: Perl Tk Panes/Frames (probably simple)
by Anonymous Monk on Sep 11, 2015 at 15:56 UTC
    Hi, here is a little example which should show you the ropes on handling the scrollbar options. It is slightly exaggerated for demo purposes. :-)
    #!/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; }