如何在 R 中为 Tk 组合框设置值

发布于 2024-10-06 00:00:24 字数 380 浏览 0 评论 0原文

有时我有一个下拉框,只有一个项目可供选择,但该项目可能是一个带有空格的字符串。我怎样才能在 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"))

任何提示表示赞赏!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携君以终年 2024-10-13 00:00:24

试试这个:

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

还有一个替代方案,实际上将字符串放入下拉列表中,而上面的方法没有:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文