开发者

How do I set values to a Tk combobox in R

I sometimes have a dropdown box with only one item to choose from, but this item might be a string with spaces. How can I do this in R? Here is the problem:

library(tcltk2)
root<-tktoplevel()
v <- 开发者_开发百科tclVar()
d <- tk2combobox(root, textvariable=v)
tkpack(d)

# works
tkconfigure(d, values=c("a string with spaces", "a second string"))

# inserts four items instead of one
tkconfigure(d, values=c("a string with spaces"))

Any hint appreciated!


Try this:

spaceystr <- tclVar("a string with spaces")
tkconfigure(d, textvariable = spaceystr)

An alternative is also available that actually puts the string in the drop-down which the above does not:

tkconfigure(d, values=as.tclObj("a string with spaces", drop=FALSE))

This is hinted at, although not actually illustrated, in the help page for TclInterface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜