Home Contact

TkDocs

Information you need to build high-quality Tk user interfaces.

close

Modern Tkinter ebook If you've found the material on this site useful, please consider purchasing this e-book (only $10), which is based on the Python material in the tutorial. Doing so helps me maintain and update this site. Thank you very much!


 
 
@markroseman
mark@markroseman.com

 

Kindle Buy now for your Kindle
Kindle apps are also available for most smartphones, tablets, and desktops. Payment and download handled by Amazon's Kindle Store.

 

PDF Buy the DRM-free PDF
Downloads handled by SendOwl.com. Payment handled via PayPal
(click "Don't have a PayPal account" to use a credit card).

Hey Python Users!
Modern Tkinter ebook 
Like TkDocs?
 
Check out the e‑book Modern Tkinter!
 

What do you mainly use Tk for?
Product my organization sells
Tool used in my organization
Free or open source project
Tool I use for my own work
Learning or playing around
Poll Maker
Widget Pictures

Listbox Widgets

Essentials

Widget Roundup

The widget roundup provides you with a quick and easy reference to the most important features and options for each Tk widget.

Listbox

Widget Essentials

When to use: To allow the user to choose one or more items from a possibly large fixed list of choices, in situations where screen real estate is not overly constrained.
Tcl usage: set listvar [list items for listbox]
tk::listbox .l -listvariable listvar
Ruby usage: $listvar = TkVariable.new ( list of items for listbox );
TkListbox.new(parent) {listvariable $listvar}
Reference: (at www.tcl.tk)

Common Options

listvariable A variable that holds the list of items contained in the listbox; changing this variable will update the items in the listbox.
height The number of rows high the listbox will request.
selectmode Whether the user can select only a single item (use a value of "browse"), or multiple items (use "extended").
yscrollcommand Used to connect the listbox to a scrollbar's "set" method.

How do I...

Find out which item(s) are currently selected? Call the "curselection" method, which returns a list of the indices (0..n-1) of the selected items.
Change which items(s) are currently selected. To deselect all items in a range, call "selection clear firstidx ?lastidx?".
To select all items in a range, call "selection set firstidx ?lastidx?".
Disable the listbox? Set the "state" configuration option to "disabled".
To re-enable, set the "state" configuration option to "normal".
Find out what item is at a given index? Look at that item in the list held in the variable named in the listvariable option.
Make sure a particular item is in view? Call the "see index" method.
Tell when the selection in the listbox changes? You can bind to the "<ListboxSelect>" virtual event.