#!/usr/local/bin/perl -w


use Tk;

$top = MainWindow->new;

$p = $top->Toplevel;
$p->Frame(-width => 50, -height => 30, -bg => 'blue')->pack;
$p->protocol('WM_DESTROY_WINDOW' => ['withdraw',$p]);
$p->withdraw;
$p->overrideredirect(1);

$anchor  = "c";
$overanchor  = "c";
$where   = $top;

sub Show
{
 $p->Popup(-popanchor  => $anchor, -overanchor => $overanchor, -popover => $where);
 $p->after(1000,['withdraw',$p]);
}

sub Anchor
{
 my ($top,$label,$var) = @_;
 my $out = $top->Frame(-label => $label,-relief => 'ridge',-borderwidth => 3);
 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;
