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.4. The Menu Widget

There are times when you won't want to use a menubutton widget. Perhaps you need to create some menus that will cascade from your menubutton. You still need to create the menus. You might also think of a way to use a menu that doesn't involve a button. For example, you could set up your application so the user right-clicks on a widget[5] and a related menu pops up, allowing the user to change configuration options.

[5] Use "<Button-3>" with bind.

It is also a good idea to be familiar with the methods for manipulating a menu, whether it's a menu widget by itself or the menu attached to a menubutton.

11.4.1. Creating the Basic Menu

To create a menu widget, invoke Menu from the desired parent of the menu:

$menu = $parent->Menu(options);

The menu widget is the only widget on which one of the geometry managers is not used directly. The menu is displayed to the user via a post directive:

$menu->post( ... );

Different arguments sent to post will determine how the menu is displayed. This method is discussed later in this chapter.

11.4.2. Menu Creation Options

As with any widget, there are options that affect how the menu widget looks and behaves. Many of the options for the menu widget were discussed in the menubutton widget portion of the chapter, so I'll only cover those that perform actions that aren't available with the menubutton widget or whose actions are different.

The following is a list of the options available for the menu widget:

-activebackground => ...

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