Classical Menubars

A classical menubar refers to the pre-Tk 8 idiom of arranging Menubutton widgets inside a Frame packed and stretched across the top of a MainWindow or Toplevel. Help Menubuttons are right justified on Unix machines. While you don’t want to write new code in this style, it’s important to know this idiom, because there’s a lot of existing code written in this manner.

The following is typical classical menubar style, except for the use of -menuitems. Luckily for us, the three menu item subroutines are identical to our previous versions and generate a menubar that looks just like Figure 12-1. Most classical menubars create Menubuttons, Menus, and menu items as described in Section 12.2.1.

use subs qw/edit_menuitems file_menuitems help_menuitems/;

my $mw = MainWindow->new;

my $menubar = $mw->Frame(qw/-relief raised -borderwidth 2/);
$menubar->pack(qw/-fill x/);

my $file = $menubar->Menubutton(qw/-text File -underline 0/,
    -menuitems => file_menuitems);
my $edit = $menubar->Menubutton(qw/-text Edit -underline 0/,
    -menuitems => edit_menuitems);
my $help = $menubar->Menubutton(qw/-text Help -underline 0/, 
    -menuitems => help_menuitems);

$file->pack(qw/-side left/);
$edit->pack(qw/-side left/);
$help->pack(qw/-side right/);

Menubutton Options

The options specified with the Menubutton command (or via the configure method) can affect the Button part of the Menubutton, both the Button and the Menu, or just the Menu.[2] The options that affect the Menu are valid for the Menu ...

Get Mastering Perl/Tk now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.