Version 29 of listbox

Updated 2003-08-08 09:48:47

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?)

Documentation


A simple example of the use of listbox (modified from the previous example, so that the scrollbar now works--D. McC) would be:

 #! /bin/sh
 # Use the shell to start the wish interpreter: \
 exec wish "$0" ${1+"$@"}

listbox .lb -selectmode multiple -height 4

 frame .f
 listbox .b -selectmode multiple -height 4
 scrollbar .c -command [list .b yview]
 .b configure -yscrollcommand [list .c set]
 .b insert 0 sample stuff colors red yellow green
 pack .b .c -in .f -side left -expand 1 -fill both
 grid .f
 .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

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