Add popup text box to R script with tcltk

I have a long-ish script to do some data analysis, and it needs to connect to multiple databases. One of the databases tends to update my password more often than I like, so I would like to add a popup to enter my current password. I found this example, but don't understand enough tcltk to see how hwo returns my value when the dialog is rejected. I was thinking of defining it as a global variable ( <<-) in the OnOK function, but that 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)
+5
source share
3 answers

You may find that the function ginput gWidgetscompletes what Greg Snow suggests:

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

NameVal NA, .

+4

: <<- tcltk - . , , CRAN, .

  library(tcltk)
  demo("tkcanvas")

, , . lastX, lastY.

+4

tkwait.window tkwait.variable. , (tkwait.window script, , , , OK). , script , script/ , .

+1

All Articles