O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

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

Using Listboxes

The lines in a listbox are indexed from zero. The keyword index end addresses the last line. Other indices are described on page 445. The most common programming task for a listbox is to insert text. If your data is in a list, you can loop through the list and insert each element at the end:

foreach item $list {
     $listbox insert end $item
}

You can insert several items at once. The next command uses eval to concatenate the list onto a single insert command:

eval {$listbox insert end}$list

It is also common to react to mouse clicks on a listbox, although the default bindings handle most of the details of selecting items. The nearest operation finds the listbox entry that is closest to a mouse event. If the mouse is clicked beyond ...

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