Create and display a list of items, one per line.
The doc for the Tk listbox is found at: http://www.purl.org/tcl/home/man/tcl8.4/TkCmd/listbox.htm
The doc for BWidget's ListBox can be found at http://tcllib.sourceforge.net/BWman/ListBox.html
(anyone want to describe how the two widgets differ? what other listbox widgets exist?)
A simple example of the use of listbox would be:
#! /usr/bin/tclsh
listbox .lb -selectmode multiple -height 4
package require Tk listbox .b -selectmode multiple -yscroll [list .b.scroll set] scrollbar .b.scroll -command [list .b yview] .b insert 0 sample stuff colors red yellow green pack .b .b itemconfigure 0 -foreground blue .b itemconfigure 1 -foreground white .b itemconfigure 2 -foreground black .b itemconfigure 3 -foreground red .b itemconfigure 4 -foreground yellow .b itemconfigure 5 -foreground green
LV: So, once .lb is created, and someone selects one of the entries, then [For some reason, the scrollbar above is not working - what is it missing?]
Often someone asks how to get a listbox to take more than one selection and people recommend they read the above reference page's information on -exportselection 0 . CJU: Normally, if you have more than one listbox on the screen, selecting one listbox automatically unselects any previous selections in the all of the others. -exportselection 0 is a way of getting around that at the cost of not being able to export the list element(s) to the X selection. I understand the reasoning for this behavior, but I think the default for -exportselection should be 0 instead of 1 for the listbox simply due to the confusion it can cause for newcomers of Tk and also the relative rarity of the need to copy from a listbox as opposed to a text or entry widget, for example. Often someone asks how to get a listbox to take more than one selection and MGS - Note: selection is not the same as the clipboard. See: selection CJU - Corrected it. MGS: Note: selection is not the same as the clipboard. See: selection
Tk's venerable FAQ covers several aspects of listbox management which are, in fact, frequently-asked. Among these are synchronization between parallel listboxes, multi-selection, ... [L1 ]. Also, note that people who start with listboxes often want to move to comboboxes, wcb, multicolumn listboxes, hugecombo, ...
Category Widget | Category Command | Tk syntax help | Arts and Crafts of Tcl-Tk Programming