Next: Other Scrolled Widgets Up: The Family of Previous: The Family of


The Scrolled Listbox Widget 

You can create a scrolled listbox widget using the tixScrolledListBox command. Notice that the widget created by the tixScrolledListBox command is not itself a listbox widget. Rather, it is a frame widget which contains two scrollbar subwidgets: one is called hsb (the horizontal scrollbar) and the other is called vsb (the vertical scrollbar). Similarly, the listbox being scrolled is also a subwidget which is appropriately called listbox. Therefore, if we need to put things into the listbox (as we always do!), we can use the subwidget method. As shown in program 2-7, we first find the pathname of the listbox subwidget by calling ``.sl subwidget listbox''. Then, we insert some items into the listbox subwidget.

tixScrolledListBox .sl -scrollbar auto
set listbox [.sl subwidget listbox]

for {set x 0} {$x $<$ 6} {incr x} {
$listbox insert end "This is item $x"

pack .sl -side left -expand yes -fill both

(Figure 2-7) Scrolled Listbox Widget 

(Figure 2-8) Scrolled ListBox with Automatic Scrollbars 

Also, as seen in the first line of program 2-7, we use the -scrollbar option to control the scrolling policy of the TixScrolledListBox widget. Usually, we'll set it to ``auto'': the scrollbars are displayed only if they are needed. Other possible values are ``both'': the two scrollbars are always displayed; ``x'': the horizontal scrollbar is always displayed, while the vertical scrollbar is always hidden; ``y'': the opposite of ``x''; ``none'': the two scrollbars are always hidden. The result of program 2-7 is shown in figure 2-8.