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

UPDATED

*I am using Perl and Tk to create a GUI.* I am making a grid that needs to have about 1000 columns and only about <50 rows. I have made this fine but if I put too much information in each cell, the program gives a strange output. I can scroll to about 800 or so depending on how much text I put in for each cell and then the other 200 disappear. The scrollbar lets me still scroll past that point but it is an empty grid.

Therefore, I am assuming I have exceeded a maximum grid size and would like to know a way around it. Thanks!

Sorry for not being more clear.

Replies are listed 'Best First'.
Re: Maximum Grid Size
by kyle (Abbot) on Sep 10, 2008 at 20:06 UTC
Re: Maximum Grid Size
by zentara (Cardinal) on Sep 10, 2008 at 21:01 UTC
    Show a minimal code example that runs and shows the problem. It's quite likely you are just making too many widgets, and need to switch to a single widget that handles many cells, something like a TableMatrix or a Canvas.

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      Ok, here is a minimal example. The effect is about the same. However, in this example the number does not start off correctly at 0. In mine, it begins the grid at the correct position. What is the same, is if you try to scroll to the end of the buttons, it cuts off.

      #!/usr/bin/perl -w # Multiple Widgets with one scrollbar.pl use Tk; require Tk::Pane; $mw = MainWindow->new(); $mw->geometry("1280x720+0+0"); $mw->title("One Scrollbar/Three Listboxes"); $mw->Button(-text => "Exit", -command => sub { exit })->pack(-side => 'bottom'); $RowDescriptFrame = $mw->Scrolled('Pane'); $RowDescriptFrame->pack(-fill => 'both'); foreach my $num (0..1000) { $RowDescriptFrame->Button(-text => "Number: $num\nAgain: $num")->g +rid(-row => 0, -column => $num, -sticky => "nsew"); } MainLoop;
Re: Maximum Grid Size
by zentara (Cardinal) on Sep 11, 2008 at 13:22 UTC
    I see your bug, and it's not due to grid size, the same thing happens with pack. I'm sure you are running into some limit with Tk::Pane, and the number of widgets it can handle. It has to do calculations during scrolling for each child widget, and it is overwhelmed by the number of widgets at the normal scrolling speed

    Use the right widget for the job, in this case, maybe a Tk::Table. This works fine.

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Table; my $mw= tkinit; #$mw->geometry("400x400+100+100"); my $table = $mw->Scrolled('Table', -rows =>1, -columns => 1000, -fixedrows => 5, #trick to hide scrollbars # -fixedcolumns => 5, -scrollbars => 'soe', -takefocus => 1,)->pack(-fill=>'both', -expand=>1); my %widgets; my $row = 1; for my $col(1..1000){ $widgets{$row}{$col} = $table->Button( -text=> "$row - $col", -background => 'white', -command => sub{ do_me($row,$col) } ); $table->put( $row,$col,$widgets{$row}{$col} ); } MainLoop; sub do_me{ my ($row, $col) = @_; print "$row $col\n"; }

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Maximum Grid Size
by Lawliet (Curate) on Sep 10, 2008 at 20:05 UTC

    Ah, well, your best bet is to get to the beach during low tide, then create the grid. That way you will be able to see all 1000 columns until high tide arrives.

    Nevermind. Could have sworn the OP was talking about drawing in the sand :P

    I'm so adjective, I verb nouns!

    chomp; # nom nom nom