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

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

Combobox

Widget Essentials

When to use: To provide the user with a set of common choices for an option (e.g. province or state), but optionally allow them to add in their own choice that isn't in the list.
Tcl usage: ttk::combobox .c -textvariable province
Ruby usage: $province = TkVariable.new ( initialValue );
Tk::Tile::Combobox.new(parent) {textvariable $province}
Reference: (at www.tcl.tk)

Common Options

textvariable A variable linked to the current value of the combobox; when the variable is changed, the current value of the combobox will be updated, while when the user changes the combobox, the variable will be updated.
values The list of values that appears in the list of choices presented to the user.
width The number of characters wide the combobox widget is onscreen; this does not constrain the number of characters it can actually hold.

How do I...

Get the current value? Look at the linked variable, or use the "get" method.
Use the "current" method (with no parameters) to return the 0-based index of which item in "values" has been selected (or -1 if none of the items in values).
Change the current value? Change the linked variable, or use the "set value" method.
To pick one of the items in the values list, you can also use the "current index" method.
Disable the entry? Use the "state disabled" method.
You can reenable this with "state !disabled".
Check with "instate disabled" (returns 1 if disabled, else 0).
Restrict choices to only those in the list? Use the "state readonly" method.
Allow other choices again with "state !readonly".
If the current value of the combobox is not in the list, and it is set to readonly mode, the current value will not be changed.
Tell when the combobox changes? You can bind to the "<ComboboxSelected>" virtual event.

Less Common Options

height The number of rows high that the pop-down list of values will be displayed.
postcommand A script which will be called right before displaying the pop-down list of choices. This can be used to more dynamically set the list of choices, via the values option.