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 ...
Get Practical Programming in Tcl & Tk, Third Edition 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.