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, "Menubars the Clunky, Casual, Old-Fashioned Way".
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/);
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.[25] The options that affect the Menu are valid for the Menu widget as well as the Menubutton widget. Here is a brief synopsis of all the options and their effects. When the description says "Affects the Button only," the behavior is the same as it would be for a Button widget.
[25] The Menubutton widget comprises other widgets (in this case, Button and Menu) to provide the overall functionality.
The following options affect only the button portion of the menubutton, and behave exactly as described in Chapter 4, " Button, Checkbutton, and Radiobutton Widgets": -cursor, -anchor, -bitmap, -borderwidth, -font, -foreground, -height, -highlightbackground, -highlightcolor, -highlightthickness, -image, -justify, -padx, -pady, -relief, -state, -takefocus, -text, -textvariable, -underline, -width, and -wraplength.
Copyright © 2002 O'Reilly & Associates. All rights reserved.