Thread weitere Funktionalität in Programm einbauen: wie anbieten? (10 answers)
Opened by Crian at 2003-11-14 14:51

coax
 2003-11-18 00:18
#44901 #44901
User since
2003-08-11
457 Artikel
BenutzerIn
[default_avatar]
Hi Crian,
kannst ja erstmal das hier nehmen, hab ich eben zusammengebaut, nur die Position des Menues sollte man etwas besser machen.

Hauptprogramm:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use Tk;
use Tk::PopupButton;

my $mw = new MainWindow;

my $menu = [[ 'command' => 'Funktion1',
             -command  => sub { print "Funktion1\n"; }],
           [ 'command' => 'Funktion2',
             -command  => sub { print "Funktion2\n"; }]];

$mw->PopupButton(-text => 'weitere Funktionen...',
                -menu => $menu
                )->pack();

MainLoop();

Modul: Tk/ButtonPopup.pm:
Code: (dl )
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
package Tk::PopupButton;

use Tk::Frame;
use Tk::Button;
@ISA = qw/Tk::Frame/;

Construct Tk::Widget 'PopupButton';

sub Populate {
   my($w, $args) = @_;

   my $menu = delete $args->{-menu};

   my $m = $w->Menu(-tearoff => 0,
                    -menuitems => $menu);

   $w->SUPER::Populate($args);

   my $b = $w->Button(-relief => 'groove')->pack(-side => 'left');
   my $ba = $w->Button(-image => $w->Bitmap(-file => 'e:/perl/site/lib/Tk/cbxarrow.xbm'))->pack(-side => 'left', -fill => 'y');

   $ba->bind('<ButtonPress-1>' => [\&popup, $m]);

   $w->ConfigSpecs(DEFAULT => [$b]);
}

sub popup {
   my($w, $m) = @_;
   $m->Popup(-popover => "cursor",
             -popanchor => 's');
}

1;
,,Das perlt aber heute wieder...'' -- Dittsche

View full thread weitere Funktionalität in Programm einbauen: wie anbieten?