use subs qw
/menus_error/;
# This demonstration script creates a window with a bunch of menus
# and cascaded menus using a menubar. A <<MenuSelect>> virtual event
# tracks the active menu item.
-title
=> 'Menu Demonstration',
my $toplevel = $TOP->toplevel;
my $menubar = $toplevel->Menu(-type
=> 'menubar');
$toplevel->configure(-menu
=> $menubar);
my $modifier = 'Meta'; # Unix
} elsif ($^O
eq 'MacOS') { # one of these days
my $f = $menubar->cascade(-label
=> '~File', -tearoff
=> 0);
$f->command(-label
=> 'Open ...', -command
=> [\
&menus_error
, 'Open']);
$f->command(-label
=> 'New', -command
=> [\
&menus_error
, 'New']);
$f->command(-label
=> 'Save', -command
=> [\
&menus_error
, 'Save']);
$f->command(-label
=> 'Save As ...', -command
=> [\
&menus_error
, 'Save As']);
$f->command(-label
=> 'Setup ...', -command
=> [\
&menus_error
, 'Setup']);
$f->command(-label
=> 'Print ...', -command
=> [\
&menus_error
, 'Print']);
$f->command(-label
=> 'Quit', -command
=> [$TOP => 'bell']);
my $b = $menubar->cascade(-label
=> '~Basic', -tearoff
=> 0);
$b->command(-label
=> 'Long entry that does nothing');
foreach $label (qw
/A B C D E F/) {
-label
=> "Print letter \"$label\"",
-accelerator
=> "$modifier+$label",
-command
=> sub {print "$label\n"},
$TOP->bind("<$modifier-${label}>" => sub {print "$label\n"});
my $c = $menubar->cascade(-label
=> '~Cascades', -tearoff
=> 0);
-command
=> sub {print "Hello\n"},
-accelerator
=> "$modifier+H",
$TOP->bind("<$modifier-h>" => sub {print "Hello\n"});
-label
=> 'Print goodbye',
-command
=> sub {print "Goodbye\n"},
-accelerator
=> "$modifier+G",
$TOP->bind("<$modifier-g>" => sub {print "Goodbye\n"});
my $cc = $c->cascade(-label
=> '~Check buttons');
$cc->checkbutton(-label
=> 'Oil checked', -variable
=> \
$OIL);
$cc->checkbutton(-label
=> 'Transmission checked', -variable
=> \
$TRANS);
$cc->checkbutton(-label
=> 'Brakes checked', -variable
=> \
$BRAKES);
$cc->checkbutton(-label
=> 'Lights checked', -variable
=> \
$LIGHTS);
-label
=> 'See current values',
-command
=> [\
&see_vars
, $MW, [
my $cc_menu = $cc->cget(-menu
);
my $rc = $c->cascade(-label
=> '~Radio buttons');
foreach $label (qw
/10 14 18 24 32/) {
-label
=> "$label point",
-variable
=> \
$POINT_SIZE,
foreach $label (qw
/Roman Bold Italic/) {
-variable
=> \
$FONT_STYLE,
-label
=> 'See current values',
-command
=> [\
&see_vars
, $MW, [
['point size', \
$POINT_SIZE],
['font style', \
$FONT_STYLE],
my $rc_menu = $rc->cget(-menu
);
my $i = $menubar->cascade(-label
=> '~Icons', -tearoff
=> 0);
-bitmap
=> '@'.Tk
->findINC('demos/images/pattern'),
-command
=> [$DIALOG_ICON => 'Show'],
foreach $label (qw
/info questhead error/) {
-command
=> sub {print "You invoked the \"$label\" bitmap\n"},
$i->cget(-menu
)->entryconfigure(2, -columnbreak
=> 1);
my $m = $menubar->cascade(-label
=> '~More', -tearoff
=> 0);
foreach $label ('An entry', 'Another entry', 'Does nothing',
'Does almost nothing', 'Make life meaningful') {
-command
=> sub {print "You invoked \"$label\"\n"},
my $k = $menubar->cascade(-label
=> 'C~olors');
foreach $label (qw
/red orange yellow green blue/) {
-command
=> sub {print "You invoked \"$label\"\n"},
$TOP->Label(qw
/-wraplength 4.5i -justify left -text/ => 'This window contains a menubar with cascaded menus. You can post a menu from the keyboard by typing Alt+x, where "x" is the character underlined on the menu. You can then traverse among the menus using the arrow keys. When a menu is posted, you can invoke the current entry by typing space, or you can invoke any entry by typing its underlined character. If a menu entry has an accelerator, you can invoke the entry without posting the menu just by typing the accelerator. The rightmost menu can be torn off into a palette by selecting the first item in the menu.', -font
=> $FONT)->pack;
$TOP->Label(qw
/-relief sunken -borderwidth 1 -anchor w/,
-font
=> 'Helvetica 10', -textvariable
=> \
$status_bar)->
pack(qw
/-padx 2 -pady 2 -expand yes -fill both/);
$menubar->bind('<<MenuSelect>>' => sub {
$label = $w->entrycget('active', -label
);
# Generate a background error, which may even be displayed in a window if
$msg = "This is just a demo: no action has been defined for \"$msg\".";