[R] Dropdown boxes in tcltk and R
Jonne Zutt
j.zutt at tudelft.nl
Mon May 14 14:37:53 CEST 2007
Hi Jake,
Two things I noticed:
- Don't tkdestroy(tt) too soon, you use comboBox later.
- Don't use fruitChoice in OnOK if you only define it at the
very end of your program.
Here's your code with these two modifications.
Greets,
Jonne.
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=FALSE,values=fruits)
tkgrid(comboBox)
OnOK <- function()
{
fruitChoice <<-
fruits[as.numeric(tclvalue(tcl(comboBox,"getvalue")))+1]
msg <- paste("Good choice! ",fruitChoice,"s are delicious!",sep="")
tkmessageBox(title="Fruit Choice",message=msg)
tkdestroy(tt)
}
OK.but <-tkbutton(tt,text=" OK ",command=OnOK)
tkgrid(OK.but)
tkfocus(tt)
tkwait.window(tt)
fruitChoice
More information about the R-help
mailing list