11.1. Different Types of Menus

There are several ways to create and utilize a menu from within your Perl/Tk application. Here are some examples of how you can use a menu-type widget:[1]

[1] Typically, a menu contains commands that aren't used frequently, such as configuration options, File Open, File Close, Help, and so on. You would be wise to put frequently accessed commands in the window to provide easier access for the user.

  • Create File, Edit, and Help menus across the top of your application.

  • Display a list of fonts from which the user can choose (the selected font can be marked with a checkmark).

  • Display a list of editing commands that become available when the user right-clicks on another object (such as a listbox or entry widget) in your window.

You can build each of these different types of menus with the basic menu widget. The menu widget itself is a list of items that are displayed one item per line in a box. Each item can have an associated callback that is called when the menu item is invoked or selected. Unlike the other widgets we have seen so far, you cannot use any of the geometry managers on a menu. Instead, you must use a method called post to display your menu widget (post will be discussed later in this chapter).

Figure 11.1. Simple menu widget with five items: Item1, Item2, Separator, Item3, and Item4

Figure 11.1 shows the contents of a typical menu widget. ...

Get Learning Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.