O'Reilly logo

Learning Perl/Tk by Nancy Walsh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.2. The Menubutton Widget

As described earlier, the menubutton widget has a menu that drops down from a button when the button is pressed. The menu is removed from the window when an item from the menu is selected or when the user clicks elsewhere in the application.

Many applications use a menubutton-type construct. The menubuttons are normally grouped across the top of the application and have names like File, Edit, Options, and Help. Figure 11.4 shows an example of several menubuttons grouped together in a frame.[2]

[2] You can accomplish this same look in a window by using a menubar widget. However, the additional functionality that it provides is minimal, so we won't be covering it in this book. To get this look, create a frame widget with a relief of "ridge" and borderwidth of 2. Pack the menubuttons with -side => "left" for all but the help menu, which has -side => "right".

Figure 11.4. Example of window with several menubuttons across the top

11.2.1. Creating a Menubutton

When you create a menubutton widget, use the parent widget to invoke the Menubutton method, which then creates a menubutton widget reference. The options you send with the Menubutton method can configure both the button that is initially displayed on the screen and the actual menu items:

$mbutton = $parent->Menubutton( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required