2010-12-04 60 views
2

我有時只有一個項目可供選擇,但該項目可能是一個帶空格的字符串。我如何在R中做到這一點?這裏是問題:如何在R中設置值到Tk組合框中

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

任何提示讚賞!

回答

3

試試這個:

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

的替代也可以說其實是把字符串中的下拉它上面沒有:

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

這是在暗示,雖然沒有實際在TclInterface的幫助頁面中進行了說明。

+0

很好用,謝謝! – 2010-12-05 11:42:46