The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -w

# XXX Does not work.
# Error message: Don't know how to handle magic of type \165
# Problem is caused by usage of -variable => $widget

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;