使用 tcltk 在 R 脚本中添加弹出文本框 [英] Add a popup text box within an R script using tcltk

查看:49
本文介绍了使用 tcltk 在 R 脚本中添加弹出文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的脚本来做一些数据分析,它必须连接到几个数据库.其中一个数据库往往比我喜欢的更频繁地更新我的密码,所以我想添加一个弹出框让我输入我当前的密码.我找到了这个例子,但不理解足够的 tcltk 来看到 hwo 在对话框被关闭时返回我的值.我想过将其定义为 OnOK 函数中的全局变量 (<<-),但这似乎很混乱

I have a long-ish script to do some data analysis, and it has to connect to several databases. One of the databases tends to update my password more frequently than I like, so I'd like to add a popup box for me to enter my current password. I found this example but don't understand enough tcltk to see hwo to return my value when the dialog box is dismissed. I've thought of defining it as a global variable (<<-) within the OnOK function, but this seems messy

require(tcltk)
tt<-tktoplevel()
Name <- tclVar("Password")
entry.Name <-tkentry(tt,width="20",textvariable=Name)
tkgrid(tklabel(tt,text="Enter Password"))
tkgrid(entry.Name)
OnOK <- function()
{
    NameVal <- tclvalue(Name)
    tkdestroy(tt)
}
OK.but <-tkbutton(tt,text="   OK   ",command=OnOK)
tkbind(entry.Name, "<Return>",OnOK)
tkgrid(OK.but)
tkfocus(tt)

推荐答案

您可能会发现 gWidgetsginput 函数包含了 Greg Snow 为您提出的建议:

You might find the ginput function of gWidgets wraps up what Greg Snow suggests for you:

require(gWidgets)
options(guiToolkit="tcltk") 
NameVal <- ginput("Enter your passsword:")

NameVal 将包含输入的字符串或 NA 如果您取消.

NameVal will contain the entered string or NA if you cancel.

这篇关于使用 tcltk 在 R 脚本中添加弹出文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆