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!



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 Payment handled via Stripe (credit cards) or PayPal.

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


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 = ( list of items for listbox ); {listvariable $listvar}
Reference: (at

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.