Debian Codegraph @

examples/table_demo

raw
1 #!/usr/local/bin/perl -w
2
3 use Tk;
4 use Tk::Table;
5
6 sub Compass
7 {
8 my ($top,$var) = @_;
9 my $out = $top->Table(-relief => 'ridge',-borderwidth => 3,-scrollbars => 'c');
10 my $i = 0;
11 foreach $r ([qw(nw n ne)],[qw(w c e)],[qw(sw s se)])
12 {
13 my $j = 0;
14 foreach $a (@$r)
15 {
16 $b = $out->Create($i,$j++,'Radiobutton',-text=> $a,
17 -variable => $var, -value => $a, -anchor => 'w');
18 }
19 $i++;
20 }
21 return $out;
22 }
23
24 my $mw = MainWindow->new;
25
26 my $t = $mw->Table(-columns => 6, -rows => 8, -fixedrows => 1, -scrollbars => 'se');
27 $t->pack(-expand=> 1, -fill => 'both');
28
29 sub Pressed
30 {
31 my ($t,$i,$j) = @_;
32 my $l = $t->Label(-text => "Pressed $i,$j",-relief => 'sunken');
33 my $old = $t->put($i,$j,$l);
34 $old->destroy if ($old);
35 }
36
37 my $i;
38 foreach $i (0..9)
39 {
40 my $j;
41 foreach $j (0..9)
42 {
43 my $l = $t->Button(-text => "Entry $i,$j",
44 -command => [\&Pressed,$t,$i,$j]);
45 $t->put($i,$j,$l);
46 }
47 }
48
49 my $sb;
50 my $rl;
51 my $cl;
52
53 tie $sb,Tk::Configure,$t,'-scrollbars';
54 tie $rl,Tk::Configure,$t,'-fixedcolumns';
55 tie $cl,Tk::Configure,$t,'-fixedrows';
56
57 Compass($mw,\$sb)->pack(-side => 'bottom');
58
59 $mw->Checkbutton(-text => 'Row labels', -variable => \$rl, -onvalue => 1, -offvalue => 0)
60 ->pack(-side => 'left');
61 $mw->Checkbutton(-text => 'Column labels', -variable => \$cl, -onvalue => 1,-offvalue => 0)
62 ->pack(-side => 'right');
63
64 $t->focus;
65 $t->update;
66
67 MainLoop;