Debian Codegraph @

examples/popup

raw
1 #!/usr/local/bin/perl -w
2
3 # XXX Does not work.
4 # Error message: Don't know how to handle magic of type \165
5 # Problem is caused by usage of -variable => $widget
6
7 use Tk;
8
9 $top = MainWindow->new;
10
11 $p = $top->Toplevel;
12 $p->Frame(-width => 50, -height => 30, -bg => 'blue')->pack;
13 $p->protocol('WM_DESTROY_WINDOW' => ['withdraw',$p]);
14 $p->withdraw;
15 $p->overrideredirect(1);
16
17 $anchor = "c";
18 $overanchor = "c";
19 $where = $top;
20
21 sub Show
22 {
23 $p->Popup(-popanchor => $anchor, -overanchor => $overanchor, -popover => $where);
24 $p->after(1000,['withdraw',$p]);
25 }
26
27 sub Anchor
28 {
29 my ($top,$label,$var) = @_;
30 my $out = $top->Frame(-label => $label,-relief => 'ridge',-borderwidth => 3);
31 foreach $r ([qw(nw n ne)],[qw(w c e)],[qw(sw s se)])
32 {
33 my $f = $out->Frame;
34 foreach $a (@$r)
35 {
36 $b = $f->Radiobutton(-text=> $a, -variable => $var, -value => $a,
37 -command => \&Show);
38 $b->pack(-side => 'left');
39 }
40 $f->pack;
41 }
42 return $out;
43 }
44
45 my $w = $top->Frame;
46 my $b = $w->Radiobutton(-text => 'Window', -variable => \$where,
47 -value => $top, -command => \&Show);
48 $b->pack(-side=>'left');
49
50 $w->Radiobutton(-text => 'Screen', -variable => \$where,
51 -value => undef, -command => \&Show)->pack(-side=>'left');
52 $w->Radiobutton(-text => 'Cursor', -variable => \$where,
53 -value => 'cursor', -command => \&Show)->pack(-side=>'left');
54 $w->pack;
55
56 Anchor($top,"Self",\$anchor)->pack(-side => 'left');
57 Anchor($top,"Over",\$overanchor)->pack(-side => 'right');
58
59 MainLoop;