in reply to Tk: Does the 'grid' geometry manager has a problem with a scrolled parent?

Hi tcarmeli,

Try this:

my ($col, $row) = $graph_pane->{'SubWidget'}->{'scrolled'}->gridSize( +);

I think that will give you the answer you're looking for (4 x 3).

You may also want to consider using strict and warnings in your code, which only requires adding 6 my declarations:

#!/usr/bin/perl -w use strict; use warnings; use Tk; use Tk::Pane; my $mw = MainWindow->new; my $graph_pane = $mw->Scrolled('Frame', -scrollbars => 'osoe', )->pack( -fill => 'both', -expand => 1, ); for my $i (0 .. 2){ for my $j (0 .. 3){ my $c=$graph_pane->Canvas( -width => 250, -height => 100, -background => 'white', )->grid( -row => $i, -sticky => "nsew", -column => $j, ); $c->createText(10,10, -text => $i . ',' . $j, -font => "{Arial} 8 bold", ); } } my ($col, $row) = $graph_pane->{'SubWidget'}->{'scrolled'}->gridSize( +); warn($col); warn($row); MainLoop;

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Tk: Does the 'grid' geometry manager has a problem with a scrolled parent?
by tcarmeli (Beadle) on Aug 07, 2006 at 15:14 UTC
    Thanks!
    It works!
    Regarding the missing 'my', I just wrote a short example, it is not my 'real' code...Thanks!
Re^2: Tk: Does the 'grid' geometry manager has a problem with a scrolled parent?
by tanyeun (Sexton) on Aug 08, 2006 at 05:49 UTC
    what does the following means:
    my ($col, $row) =$graph_pane->{'SubWidget'}->{'scrolled'}->gridSize();
    I had the error message:
    Can't call method "gridSize" on an undefined value at tes7 line 23.
      Hi tanyeun,

      It's difficult to know what's causing the error without seeing a bit more information.

      Are you sure you've created graph_pane correctly?

      Try putting this near the beginning of your code:

      use Data::Dumper; $Data::Dumper::Indent = 1;

      and just before the line where the error occurs (Can't call method "gridSize" on an undefined value at tes7 line 23) put this:

      printf "graph_pane => %s\n", Dumper(\$graph_pane);

      Assuming that graph_pane was assigned correctly, it should display the entire underlying data structure.  For example, I get:

      graph_pane => $VAR1 = \bless( { 'SubWidget' => { 'scrolled' => bless( { '_After_' => { 'after#3' => bless( [ ${$VAR1}->{'SubWidget'}->{'scrolled'}, 'after#3', 'idle', 'once', bless( [ 'Manage', ${$VAR1}->{'SubWidget'}->{'scrolled'}, bless( { # # ...Many lines omitted... # }, 'Tk::Frame' );

      Did you get something like the above, or something completely different?


      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
        well, I got this:
        graph_pane => $VAR1 = \bless( { '_Destroy_' => [ bless( [ sub { "DUMMY" } ], 'Tk::Callback' ) ], 'SubWidget' => { 'frame' => bless( { 'Configure' => { '-background' => '#C6C6B2B2A8A8', '-foreground' => '#000000000000', '-labelVariable' => undef }, '_#canvas' => 11, '_TkValue_' => '.frame.frame', 'ConfigSpecs' => { '-fg' => '-foreground', '-background' => [ [ 'SELF' ], 'background', 'Background', '#C6C6B2B2A8A8' ], '-label' => [ 'METHOD', undef, undef, undef ], '-bg' => '-background', '-foreground' => [ [ 'PASSIVE' ], 'foreground', 'Foreground', '#000000000000' ], 'DEFAULT' => [ 'SELF' ], '-labelPack' => [ 'METHOD', undef, undef, undef ], '-labelVariable' => [ 'METHOD', undef, undef, undef ] } }, 'Tk::Frame' ) }, '_#frame' => 0, 'Configure' => { '-background' => '#C6C6B2B2A8A8', '-foreground' => '#000000000000', '-scrollbars' => 'osoe', '-labelVariable' => undef }, 'Delegates' => { 'DEFAULT' => ${$VAR1}->{'SubWidget'}->{'frame'}, 'bindtags' => ${$VAR1}->{'SubWidget'}->{'frame'}, 'bind' => ${$VAR1}->{'SubWidget'}->{'frame'} }, '_After_' => { 'after#1' => bless( [ ${$VAR1}, 'after#1', 'idle', 'once', bless( [ ${$VAR1}, 'packscrollbars' ], 'Tk::Callback' ) ], 'Tk::After' ) }, '_TkValue_' => '.frame', '-scrollbars' => 'osoe', 'ConfigSpecs' => { '-fg' => '-foreground', '-background' => [ ${$VAR1}->{'SubWidget'}->{'frame'}, 'background', 'Background' ], '-label' => [ 'METHOD', undef, undef, undef ], '-bg' => '-background', '-foreground' => [ ${$VAR1}->{'SubWidget'}->{'frame'}, 'foreground', 'Foreground' ], 'DEFAULT' => [ ${$VAR1}->{'SubWidget'}->{'frame'} ], '-labelPack' => [ 'METHOD', undef, undef, undef ], '-scrollbars' => [ 'METHOD', 'scrollbars', 'Scrollbars', 'se' ], '-labelVariable' => [ 'METHOD', undef, undef, undef ] }, 'pack_pending' => 1 }, 'Tk::Frame' );
        I completely doesn't know what it says...|||