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