[R] initial value in ComboBox tkwidget

Alexander juschitz_alexander at yahoo.de
Thu Oct 6 15:12:55 CEST 2011


Hello,
I took me very long to find out how to set the initial value in the combobox
widget in tk (see the example below). My question is now : Why does
"textvariable" has to be a tclVar while "values" can be a normal vector? My
next question is: How could I have known this much earlier? Is there a
documentation for the tcl/tk usage in R? I know a lot of website with
example. But the documentation is not very complet. Any tipps?

require(tcltk)
tclRequire("BWidget")
tt <- tktoplevel()
tkgrid(tklabel(tt,text="What's your favorite fruit?"))

fruits <- c("Apple","Orange","Banana","Pear")
comboBox <-
tkwidget(tt,"ComboBox",editable=TRUE,values=fruits,textvariable=tclVar("Banana"))
tkgrid(comboBox)

OnOK <- function()
{
    fruitChoice <- fruits[as.numeric(tclvalue(tcl(comboBox,"getvalue")))]
    tkdestroy(tt)
    msg <- paste("Good choice! ",fruitChoice,"s are delicious!",sep="")
    tkmessageBox(title="Fruit Choice",message=msg)

}
OK.but <-tkbutton(tt,text="   OK   ",command=OnOK)
tkgrid(OK.but)
tkfocus(tt)




--
View this message in context: http://r.789695.n4.nabble.com/initial-value-in-ComboBox-tkwidget-tp3878164p3878164.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list