Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

[R] Dropdown boxes in tcltk and R

jake

2007-05-13

Replies:

Hello,

I'm very much a newbie in R and more so in tcltk so apologies if this
question is stupid. Basically I am trying to use the combobox example
found here:
http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/DropDown.html .

What I want to do is in that example get fruitChoice as a variable in R
in general. When I run that code, however, and the ask for fruitChoice
it says 'error not found'. I suspect it's because its embedded in a
function, but I can't work out how to unravel it. I've tried something
like this to no avail.

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()
{
  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)

tkwait.window(tt)

fruitChoice <- fruits[as.numeric(tclvalue(tcl(comboBox,"getvalue")))+1]

fruitChoice

Which gives me:

Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"),
class = "tclObj") :
    [tcl] invalid command name ".14.2".

What do I need to change to get the variable? That is, if I pick
"orange", I want a variable with the value "orange".

Thanks for your reply, I'm sure this is something simple I've overlooked,

Jake

______________________________________________
R-help@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
©2008 r-help.com - Jax Systems, LLC, U.S.A.