2

我有时有一个下拉框,只有一个项目可供选择,但这个项目可能是一个带空格的字符串。我怎样才能在 R 中做到这一点?这是问题所在:

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"))

任何提示表示赞赏!

4

1 回答 1

3

试试这个:

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

还有一种替代方法,它实际上将字符串放在上面没有的下拉列表中:

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

在 TclInterface 的帮助页面中暗示了这一点,尽管没有实际说明。

于 2010-12-04T17:13:38.743 回答