Perl Tk TableMatrix Widget Help

Perl Tk TableMatrix Widget Help

I was told that perl/tk is a nice perl gui but is very badly documented. Well I can confirm I was told correctly.

Most recently I had some trouble with Tk:TableMatrix which is very poorly documented. The biggest annoyance I had was that TableMatrix is not compatible with ActivePerl 811 the most recent version. I found on a non english site that TableMatrix is compatible with 809. And I found that answer after a few hours of trying to figure out why my script would not run.

I also found out that when the documentation says to pass 4 values to -bd to describe {left right top bottom} border they really mean a refence to an array with four variables.

So I hope the posting of the following code will help others with TableMatrix.

Sample Tk::TableMatrix Code


use Tk;
use Tk::TableMatrix::Spreadsheet;

$mw = MainWindow->new;
$mw->configure(-title=>’ID3 Tag Genre and Year Fixer’);
$mw->minsize(qw(500 200));
$menu = $mw->Frame()->pack(-side=>’top’,-fill=>’x’);
$menu_file = $menu->Menubutton(-text=>’File’,-tearoff=>’false’)->pack(-side=>’left’);
$frame = $mw->Frame(-height=>’10’,-width=>’30’,-relief=>’groove’,-borderwidth=>’3′)->pack(-fill=>’x’,-pady=>’0′);

@border = (0,0,0,1);

$arrayVar->{"0,0"} = "%";
$arrayVar->{"0,1"} = "Artist";
$arrayVar->{"0,2"} = "Album";
$arrayVar->{"0,3"} = "Year";
$arrayVar->{"0,4"} = "Genre";
$table = $frame->Scrolled(‘Spreadsheet’,
?-cols => 5,
?-width => 5, -height => 6,
?-titlerows => 1,
?-variable => $arrayVar,
?-selectmode => ‘multiple’,
?-selecttype => ‘row’,
?-resizeborders => ‘col’,
?-bg => ‘white’,
?-rowheight => 2,
?-bd => \@border,
?-justify => ‘left’,
?-drawmode => ‘compatible’,
?-wrap => 0,
?-relief => ‘solid’
$table->tagConfigure(‘title’, -bd=>2, -relief=>’raised’);

4 thoughts on “Perl Tk TableMatrix Widget Help

  1. Hi Kevin,
    as a Perl/Tk novice I ran into same compatibility problems as you mentioned, but your advice to fetch ana adaequate compiled version form an other site was very helpful, now it works well…thank you!

    however, the documentation as you mentioned already is quite poor.

    I would like to ask you about a problem I figured out recently, maybe you have some advice concerning this issue as well 😉

    It is possible to define some kind of %titlehash with newline characters, assign it to variable option and text separated by newline is displayed correctly. Checkout:

    my $titleHash = {
    “0,0” => “abc”,
    “0,1” => “1234\nfoo”,

    my $table;
    $table = $mw->Scrolled(‘TableMatrix’,
    -titlerows => 1,
    -roworigin => 0,
    -colorigin => 0,
    -cols => 2,
    -rowheight => 2,
    -variable => $titleHash,

    $table->pack(-expand => 1, -fill => ‘both’);

    BUT if you try to do it for a single cell, it does not work!
    Check out this little subroutine


    sub PushRow {
    my $row = shift;
    my $foo = ‘123456’;

    my %CellValue = ( 0 => “123”,
    1 => “abcd\n$foo”,

    for $col (0..1) {

    } # End PushRow

    Obviously, title and ordinary cells are handled in a different way. Maybe this reason is related to -colseparator/-rowseparater stuff, which are used for copy&paste actions. I don’t know.

    Do you maybe know maybe another forum where I could stress this issue?

    Anyway, many thanks in advance!


  2. I like what you tried to do.

    c:\…\tk ==>perl -v

    This is perl, v5.8.8 built for MSWin32-x86-multi-thread
    (with 21 registered patches, see perl -V for more detail)

    Copyright 1987-2006, Larry Wall

    Binary build 816 [255195] provided by ActiveState
    Built Mar 1 2006 18:00:52
    Tk-TableMatrix 1.21: up to date. from the ActiveState repositories.

    I just upgraded. I was again going to try TableMatrix, but thought I would google for examples. I found yours.

    I clipped and saved your sample, and I get this:
    c:\…\tk ==>
    Had to create Tk::XlibVtab unexpectedly at C:/Perl/lib/ line 253.
    2eb48f4 is not a hash at C:/Perl/site/lib/Tk/ line 190.

    abnormal program termination

  3. Hi All,
    I am getting a strange problem with spreadsheet.
    When the number of rows is greater than 1000, then the program
    is being terminated on clicking the mouse on the title bar.
    But it is working fine with less than 1000 rows.

    My program is something like this:

    $customize_spreadsheet_New_Upper = $customize_dlg_topFrame_New->Scrolled(
    ‘Spreadsheet’,-rows=>21, -cols => 11,
    -width => 6, -height => 6,
    -titlerows => 1, -titlecols => 1,
    -variable => $arrayVar,
    -selectmode => ‘extended’,
    -resizeborders => ‘both’,
    -drawmode=> ‘compatible’,
    -titlerows => 1,
    -titlecols => 1,
    -bg => ‘white’,
    )->pack(qw/-expand 1 -fill both -padx 10 -pady 5/);

    $arrayVar->{“0,1”} = “Value”;

    Now I am inserting into it in the following way.
    my $used_rows_new_upper = 0;

    sub updateSpreadSheetData{
    for( 0..1000){

    sub insertIntoSpreadSheet{
    $arrayVar->{“$used_rows_new_upper,1”} = “Value1”;

    I don’t know whether it is a bug of TK or mine.
    Please let me know in case of any issue.
    I am waiting for your reply.

    Thanks & regards,

Leave a Reply

Your email address will not be published. Required fields are marked *