Debian Codegraph @

examples/popup_menu

raw
1 #!/usr/local/bin/perl -w
2 use strict;
3
4 use Tk;
5
6 my $top = MainWindow->new;
7
8 my $p = $top->Menu(-menuitems =>
9 [ '------',
10 [Button => 'Quit', -command => ['destroy' => $top]],
11 '------'
12 ]);
13
14 my $anchor = "c";
15 my $overanchor = "c";
16 my $where = $top;
17
18 sub Show
19 {
20 $p->Popup(-popanchor => $anchor, -overanchor => $overanchor, -popover => $where);
21 }
22
23 sub Anchor
24 {
25 my ($top,$label,$var) = @_;
26 my $out = $top->Frame(-label => $label,-relief => 'ridge',-borderwidth => 3);
27 my $r;
28 foreach $r ([qw(nw n ne)],[qw(w c e)],[qw(sw s se)])
29 {
30 my $f = $out->Frame;
31 foreach $a (@$r)
32 {
33 $b = $f->Radiobutton(-text=> $a, -variable => $var, -value => $a,
34 -command => \&Show);
35 $b->pack(-side => 'left');
36 }
37 $f->pack;
38 }
39 return $out;
40 }
41
42 my $w = $top->Frame;
43 my $b = $w->Radiobutton(-text => 'Window', -variable => \$where,
44 -value => $top, -command => \&Show);
45 $b->pack(-side=>'left');
46
47 $w->Radiobutton(-text => 'Screen', -variable => \$where,
48 -value => undef, -command => \&Show)->pack(-side=>'left');
49 $w->Radiobutton(-text => 'Cursor', -variable => \$where,
50 -value => 'cursor', -command => \&Show)->pack(-side=>'left');
51 $w->pack;
52
53 Anchor($top,"Self",\$anchor)->pack(-side => 'left');
54 Anchor($top,"Over",\$overanchor)->pack(-side => 'right');
55
56 MainLoop;