Debian Codegraph @

demos/basic

raw
1 ## basic
2 ##
3 ## This demo shows the basic use of the table widget
4 ##
5 ## [email protected]
6
7
8 use Tk;
9
10 use Tk::TableMatrix;
11
12 use Data::Dumper qw( DumperX);
13 my $top = MainWindow->new;
14
15 my $arrayVar = {};
16
17 foreach my $row (-1..6){
18 foreach my $col (-2..5){
19 $arrayVar->{"$row,$col"} = "r$row, c$col";
20 }
21 }
22
23 ## Test out the use of a callback to define tags on rows and columns
24 sub rowSub{
25 my $row = shift;
26 return "OddRow" if( $row > 0 && $row % 2)
27 }
28 sub colSub{
29 my $col = shift;
30 return "OddCol" if( $col > 0 && $col%2) ;
31 }
32
33 my $label = $top->Label(-text => "TableMatrix v1 Example");
34
35 my $t = $top->Scrolled('TableMatrix', -rows => 8, -cols => 8,
36 -width => 6, -height => 6,
37 -titlerows => 1, -titlecols => 2,
38 -variable => $arrayVar,
39 -roworigin => -1, -colorigin => -2,
40 -rowtagcommand => \&rowSub,
41 -coltagcommand => \&colSub,
42 -colstretchmode => 'last',
43 -rowstretchmode => 'last',
44 -selectmode => 'extended',
45 -sparsearray => 0,
46 );
47
48 my $button = $top->Button( -text => "Exit", -command => sub{ $top->destroy});
49
50 # hideous Color definitions here:
51 $t->tagConfigure('OddRow', -bg => 'orange', -fg => 'purple');
52 $t->tagConfigure('OddCol', -bg => 'brown', -fg => 'pink');
53
54 $t->colWidth( -2 => 7, -1 => 7, 1=> 5, 2 => 8, 4=> 14);
55
56 $label->pack( -expand => 1, -fill => 'both');
57
58 $t->pack(-expand => 1, -fill => 'both');
59 $button->pack(-expand => 1, -fill => 'both');
60
61 my $variable = $t->cget( -var);
62
63
64
65 Tk::MainLoop;