Create a menubutton with the Menubutton method. For example:
$mainwindow->Menubutton(-text => "File", -menuitems => [ [ command => "New", -command => \&newfile, -underline => 0 ], [ command => "Open", -command => \&openfile, -underline => 0 ], "-", [ command => "Save", -command => \&savefile, -underline => 0 ], [ command => "SaveAs", -command => \&saveasfile, -underline => 4 ] ] );
The -menuitems option takes a list of lists describing the menu items. For each menu item, an embedded anonymous list describes the type of menu item, the label to use, and the action to take when it is selected along with any other options desired to configure the menu item. In this example, each of the menu items is the command type, and we use the -command option for each item to point to the callback to execute when the menu item is selected. We also use the -underline option to enable the user to select a menu item using keystrokes. (\[quotedbl]- represents a separator between menu items.)
In addition to command, other types of menus are:
You can configure both the menu itself and the individual menu items. The configuration options that apply to Menubutton are: -activebackground, -active-foreground, -anchor, -background, -bg, -bitmap, -borderwidth, -bw, -cursor, -disa-bledforeground, -font, -foreground, -fg, -height, -highlightbackground, -high-lightcolor, -highlightthickness, -image, -justify, -padx, -pady, -relief, -state, -takefocus, -underline, -width, and -wraplength.
Other Menubutton options are:
In addition to the menu itself, each individual menu item can be configured. The widget configuration options that apply to menu items are: -activebackground, -background, -bg, -bitmap, -font, -foreground, -fg, -image, -state, and -underline. Other options are:
In addition to configure and cget, the following methods are defined for Menubutton widgets:
$menubutton->AddItems([command => "Print", -command => \&printscreen ], [command => "Exit", -command => \&exitclean ]);
$menubutton->command(-label => "Print", -command => \&printscreen); $menubutton->command(-label => "Exit", -command => \&exitclean);
$menubutton->checkbutton(-label => "Show Toolbar", -variable => \$toolbar);
$menubutton->radiobutton(-label => "Red", -variable => \$color); $menubutton->radiobutton(-label => "Blue", -variable => \$color);
Copyright © 2002 O'Reilly & Associates. All rights reserved.