I have found that I can set column widths using $wg->colWidth
Also I want to set characteristics (for example colour, state) of individual cells of a tablematrix.
So far, the only way I have found of setting the a cell’s colour and state is to:
1. Define a tag with the characteristics I want;
2. Use $wg->tagCell to add one of the defined tags to the cell.
This works as the code below shows. Is this the preferred way of setting cell characteristics?
#!/usr/bin/perl
use Tk;
use Tk::TableMatrix;
my $mw = MainWindow->new;
my (%wg, %hashv);
print "Filling Array...\n";
my ($rows,$cols) = (10, 10);
foreach my $row (0..($rows-1)){
foreach my $col (0..($cols-1)){
$hashv{t1}{"$row,$col"} = 2*$row + 3*$col;
$hashv{t2}{"$row,$col"} = 2*$row + 3*$col + 100;
}
}
print "Creating Table t1\n";
$wg{t1} = $mw->Scrolled('TableMatrix', -rows => $rows, -cols => $cols,
-width => 10, -height => 10,
-titlerows => 1, -titlecols => 1,
-variable => \%{$hashv{t1}},
-coltagcommand => \&colSub1,
-browsecommand => \&tbmx_browse_cmd_t1,
-colstretchmode => 'last',
-rowstretchmode => 'last',
-selectmode => 'extended',
-selecttitles => 0,
-drawmode => 'slow',
-scrollbars=>'se'
);
$wg{t1}->grid(-row => 0, -column => 0);
# set the column widths
$wg{t1}->colWidth(0 => 2, 1 => 4, 2 => 6, 4 => 8);
# defining tags
$wg{t1}->tagConfigure('dis', -state => 'disabled', -bg => 'yellow');
$wg{t1}->tagConfigure('red', -bg => 'red');
$wg{t1}->tagCell('dis',"1,1");
$wg{t1}->tagCell('dis',"1,2");
$wg{t1}->tagCell('dis',"1,3");
$wg{t1}->tagCell('red',"3,1");
$wg{t1}->tagCell('red',"3,2");
$wg{t1}->tagCell('red',"3,3");
#=====================================================
#
# tbmx_browse_cmd_t1
#
# browse command for table matrix t1
#
#=====================================================
sub tbmx_browse_cmd_t1() {
my ($previous_index, $actual_index) = @_;
my ($row, $col) = split ',', $actual_index;
print "[tbmx_browse_cmd_t1] index actual <$actual_index> previous <$pr
+evious_index> row <$row> col <$col>\n";
}
Tk::MainLoop;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.