| 1 |
#!/usr/local/bin/perl -w |
| 2 |
|
| 3 |
require 5.003; |
| 4 |
use English; |
| 5 |
use Tk; |
| 6 |
use Tk::Menu; |
| 7 |
use Tk::Menubutton; |
| 8 |
|
| 9 |
{ |
| 10 |
package NoisyButton; |
| 11 |
require Tk::Menu::Item; |
| 12 |
use base 'Tk::Menu::Button'; |
| 13 |
|
| 14 |
Construct Tk::Menu 'NoisyButton'; |
| 15 |
|
| 16 |
sub PreInit |
| 17 |
{ |
| 18 |
my ($class,$menu,$minfo) = @_; |
| 19 |
$minfo->{'-command'} = sub { print "$minfo->{-label} pressed.\n";}; |
| 20 |
} |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 25 |
|
| 26 |
$mw = MainWindow->new; |
| 27 |
$mw->title('Menuitem demo'); |
| 28 |
|
| 29 |
$MB = $mw->Menubutton(-text => 'File'); |
| 30 |
$M = $MB->Menu(-menuitems => [ |
| 31 |
[Button => 'Howdy', -command => sub{print "Howdy\n";}], |
| 32 |
[NoisyButton => 'Noisy'], |
| 33 |
[Button => 'Quit', -command => sub{exit}], |
| 34 |
]); |
| 35 |
$MB->configure(-menu => $M); |
| 36 |
$MB->pack(-side => 'top'); |
| 37 |
|
| 38 |
MainLoop; |
| 39 |
exit; |
| 40 |
# End of Menuitem demo |