# set up the Tk::TableMatrix grid my $grid = $mw->Scrolled('TableMatrix', -scrollbars => 'osoe', -sparsearray => 0, -titlecols => 1, # first col does not scroll -titlerows => 1, # top row does not scroll -roworigin => -1, # first scrolling (data) row is 0 -colorigin => -1, # first scrolling (data) col is 0 -padx => 2, -colwidth => 20, -anchor => 'w', -background => 'white', -resizeborders => 'none', -justify => 'left', -browsecommand => \&clickLeft, )->pack( -side =>'right', -expand => 1, -fill => 'both', ); # collect the data # column labels my @colLabels = qw( column labels here ... etc ); # from database my $data = $dbh->selectall_arrayref($sql); # number of columns my $cols = scalar @{$data->[0]}; # number of rows my $rows = 20; # populate the grid with data # hashref to hold Tk type list for grid values my $vals = {}; # add column labels to first row for (0..$cols -1){ $vals->{"-1,$_"} = $colLabels[$_]; } # add data to subsequent rows for my $ro (0..$rows -1){ # put row numbering into first column $vals->{"$ro,-1"} = $ro +1; # put data from Perl array ref into Tk list for my $co (0..$cols -1){ $vals->{"$ro,$co"} = $data->[$ro][$co]; } } # configure binds Tk list to the grid $grid->configure( -rows => $rows +1, -cols => $cols +1, -variable => $vals, );