The menubutton widget is used to conveniently group and list a number of possible actions that the user can choose from. A familiar example is in an editor, where a ``File'' menu button usually has associated with it options to open, save, close, and print a file. The basic syntax is
my $menub = $mw->Menubutton( [ option => value ] );
Some basic options are An example is as follows:
# file
use Tk;
use strict;
use warnings;
my $mw = MainWindow->new;
my $menub = 
  $mw->Menubutton( -text => 'Menu',
                   -menuitems => [
                                  ['command' => 'Hello',
                                   -command => [\&print_it, 'Hello']],
                                  ['command' => 'Bonjour',
                                   -command => [\&print_it, 'Bonjour']],
                                  ['command' => 'Goodbye',
                                   -command => [\&print_it, 'Goodbye']],
my $exit = $mw->Button(-text => 'Exit',
                      -command => [$mw => 'destroy']);
sub print_it {
  my $string = shift;
  print "You chose '$string' ...\n";
whose window appears below.

Figure 3.19: Example of a menubutton
Image menu

The '-' entry in the -menuitems option is used to insert a separator between the preceding and following menu item.

Randy Kobes 2003-11-17