-->
Previous Table of Contents Next


Menus and Menu buttons

Menu widgets are used to implement pull-down menus, cascading menus, and pop-up menus. A menu is a top-level widget that contains a set of menu entries that have values or commands associated with them. Five kinds of entries can be used in menus:

  Cascade entries display a submenu when the mouse pointer passes over them. The cascade entry is similar in function to the menu button widget.
  Command entries invoke a Tcl script when activated. The command entry is similar to the button widget in function.
  Check button entries toggle a program option between on and off. When the check button is shaded the option is on, and when the check button is not shaded it is off. The check button entry is similar in function to the check button widget.
  Radio button entries toggle a program option. The difference between the radio button entry and the check button entry is that radio buttons are typically defined in groups, with the restriction that only one of the radio buttons in the group can be active at once. The radio button entry is similar in function to the radio button widget.
  Separator entries display a horizontal line in the menu. This is used for appearance purposes only. There is no behavior associated with a separator entry.

The main difference between the menu entries and the button widgets is that the button widgets can exist by themselves, but the menu entries must exist within the context of a menu widget.

Menu button widgets are similar to button widgets. The only real difference between the two is that when menu buttons are invoked they bring up menus instead of executing Tcl scripts as button widgets do. The menu button name usually describes the types of menu entries contained in the menu that the menu button activates. This means that you will find menu entries that perform some kind of file operations contained within the File menu.

You can activate a menu by moving the mouse pointer to the menu button widget and pressing the left mouse button. This activates the menu associated with the menu button and displays the menu entries that are contained in that menu to the screen. You can now move the mouse pointer down through the list of menu entries and select the one you want.

The File menu contains two command entries (the Open entry and Quit entry), one cascade entry (the Save As entry), and one separator entry. The menu that comes up as a result of clicking the mouse pointer on the Save As cascade entry contains three command entries: the Text entry, the Ver 1 file entry, and the Ver 2 file entry.

List Boxes

The list box widget enables users of a Tk application to select items from a list of one or more items. If the number of items to be displayed in the list box is larger than the number of lines in the list box, you can attach scrollbars to make the extra items accessible.

Scrollbars

Scrollbar widgets are used to control what is displayed in other widgets. Scrollbar widgets are attached to other widgets to allow users to scroll up and down through the information contained in the widget. You typically put scrollbars on any widget that is designed to contain an arbitrary number of lines of information (such as a list box) or on widgets that contain more lines of information than the widget can display, given its size.

Summary

This chapter starts off by introducing Tcl and the Tk tool kit and describes the uses of both. Although this chapter contains a lot of information, it barely scratches the surface of the programming tools provided by Tcl and the Tk tool kit.

Tcl has many more programming features than described in this book. Some of the most notable are arrays, lists, and procedures. Not all of the Tk widgets are described here, either. Some of the widgets we did not go into are canvasses, scales, labels, messages, and textedit widgets. If you are interested in learning more about Tcl and Tk, check out a book on the subject.

Tk is just one example of an extension to Tcl. There are many other extensions available that extend the behavior of Tcl in different ways. Some of these extensions are as follows:

  Ak: An audio extension for Tcl, Ak provides numerous commands for sound recording and playback.
  XF: An interactive graphical user interface developer for Tk.
  Tcl-DP: A Tcl extension that helps programmers develop distributed applications using Tcl.

To learn more about

Other compilers that are supported on Linux, see Chapter 30, “Other Compilers.”
CGI programming, which Perl is particularly well suited for, see Chapter 52, “CGI Scripts.”


Previous Table of Contents Next