[R-gui] TclTk dynamic dropdown list combo box

"João G." joaofgo at gmail.com
Fri Jun 25 00:16:56 CEST 2010


Thank you! That worked out nicely.
I leave here the code used in case it turns out useful for someone else:

#
##
require(tcltk)
tclRequire("BWidget")

tt <- tktoplevel()
tkwm.title(tt,"Test GUI")
tkgrid(tklabel(tt,text="Test label"))
ttframe<-tkframe(tt,relief="groove",borderwidth=2)

x<<-cbind(x=rep(LETTERS[1:3],each=4),y=1:12)
v<-tclVar("A")
z<-x[x[,1]==tclvalue(v),2]

entry.v<-tkentry(ttframe,width="30",textvariable=v)
label.v<-tklabel(ttframe,text=tclvalue(v))
tkconfigure(label.v,textvariable=v)

tkgrid(entry.v)
tkgrid(tklabel(ttframe,text=""))
tkgrid(label.v)

getVal<-function(){
     z<-x[x[,1]==tclvalue(v),2]
     tkconfigure(comboBox,values=z)
}

comboBox<-tkwidget(ttframe,"ComboBox",editable=FALSE,values=z)
button.getValues<-tkbutton(ttframe,text="Get values",command=getVal)
tkgrid(comboBox,button.getValues)
tkgrid(ttframe)

tkgrid(tklabel(tt,text=""))
tkfocus(tt)

#
# Type B or C in the text entry field and press the button "Get values".
# This will update the values in the dropdown field

Best regards,
João Gonçalves.

24-06-2010 22:50, Greg Snow:
> Create and pack a combo box (possibly with dummy entries), then when you want to dynamically change the options call tkconfigure( comboboxobject, values = vectorwithvalues )
>
> I think that should work, but have not tested it specifically for your case (my tkexamp function in the TeachingDemos package does something like this, but not after an entry has been filled).
>
>



More information about the R-SIG-GUI mailing list