next up previous contents
Next: Menus Up: Basic Widgets Previous: Scrollbars

Listboxes

A ListBox.htmllistbox has a list of several items, from which you can select one. Listboxes can be scrollable, which is most helpful since they can hold more items than are visible at a given time.

Just like entries, list boxes are a polymorphic type, created with the function newListBox with the by now familiar signature. As opposed to entries, list boxes (quite obviously) have lists of values:

  
Figure 4: A list box.

When the user selects something from the the listbox, Tk's selection is set, which can be queried with the methods of the module Selection.htmlSelect, in particular getSelection. No event is generated per se -- if you want that, you need to bind the left mouse button (which generates the selection).

Table 1 shows a short example which demonstrates the usage of listboxes, selections and scrollbars. Note the type constraint on the newListBox -- we need this to force the type to String, since it can not be inferred. Fig. 4 shows a screenshot.

  
Table 1: Example program for list boxes and scrollbars.

The position of entries in a list box can be indexed with instances of the class HasIndex. For more on indices, see Section 6.1, but the important instances here are

In other words, the index is a number (starting with 0), the EndOfText (only constructor of the synonymous data type), or the element itself.

A configuration particular to list boxes is the selection mode. The SelectMode is an enumeration of four constructors, which determine the way elements are selected in a list box:

Selections are handled by the selection classes (see Section 6.2) below. You can set the selection, or query the current selection as in the code above.


next up previous contents
Next: Menus Up: Basic Widgets Previous: Scrollbars

Christoph Lueth
Wed May 29 13:20:38 MEST 2002