Search code examples
tclincr-tcl

change the iwidgets::combobox selected value tcl/tk


How to change the iwidgets::combobox selected value in tcl/tk?

variable check [iwidgets::combobox  .check -labeltext "aaaa" -selectioncommand aaa_update]  
eval .check  insert list 0 aaa bbb

I tried the following and it doesn't work. (set ::check_tech "bbb")


Solution

  • To manipulate what is selected, you use the selection method:

    .check selection clear 0 end
    .check selection set 1
    

    The 1 is because bbb is the second item in the dropdown listbox, and Tcl/Tk counts indices from zero almost always (and definitely so in this case). You have to clear the selection before setting it because the underlying model of the listbox used to power the combobox supports multiple selected things at once, even though that doesn't make much sense in this case.