I can set up an entry widget (thanks to an old
post by Barry Rowlingson) that gets a password and
exits when the user clicks on the "OK" button.
Anyone have any clever ideas for returning/
destroying the window when the user types a carriage
return/ENTER in the text window? I've messed around
a little with validate, validatecommand, but don't
see any obvious way to do it ...
getPassword <- function(){
require(tcltk)
tt <- tktoplevel()
pass=tclVar("")
label.widget <- tklabel(tt, text="Enter Password")
password.widget <- tkentry(tt,show="*",textvariable=pass)
ok <- tkbutton(tt,text="OK",default="active",
command=function()tkdestroy(tt))
tkpack(label.widget, password.widget,ok)
tkwait.window(tt)
return(tclvalue(pass))
}
thanks
Ben Bolker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL:
<https://stat.ethz.ch/pipermail/r-help/attachments/20080811/8396b09c/attachment.bin>
2008/8/11 Ben Bolker <bolker at zoology.ufl.edu>:> > I can set up an entry widget (thanks to an old > post by Barry Rowlingson) that gets a password and > exits when the user clicks on the "OK" button.Who? Oh dear, my past comes back to haunt me...> getPassword <- function(){ > require(tcltk) > tt <- tktoplevel() > pass=tclVar("") > label.widget <- tklabel(tt, text="Enter Password") > password.widget <- tkentry(tt,show="*",textvariable=pass) > ok <- tkbutton(tt,text="OK",default="active", > command=function()tkdestroy(tt)) > tkpack(label.widget, password.widget,ok) > tkwait.window(tt) > return(tclvalue(pass)) > }tkbind a function on the entry widget so that if <Return> is pressed it destroys the window: getPassword=function(){ require(tcltk) tt <- tktoplevel() pass=tclVar("") label.widget <- tklabel(tt, text="Enter Password") password.widget <- tkentry(tt,show="*",textvariable=pass) tkbind(password.widget,"<Return>",function(){tkdestroy(tt)}) ok <- tkbutton(tt,text="OK",default="active", command=function()tkdestroy(tt)) tkpack(label.widget, password.widget,ok) tkwait.window(tt) return(tclvalue(pass)) } How's that? See you in a few years... Barry
2008/8/11 Ben Bolker <bolker at zoology.ufl.edu>:> > I can set up an entry widget (thanks to an old > post by Barry Rowlingson) that gets a password and > exits when the user clicks on the "OK" button.Who? Oh dear, my past comes back to haunt me...> getPassword <- function(){ > require(tcltk) > tt <- tktoplevel() > pass=tclVar("") > label.widget <- tklabel(tt, text="Enter Password") > password.widget <- tkentry(tt,show="*",textvariable=pass) > ok <- tkbutton(tt,text="OK",default="active", > command=function()tkdestroy(tt)) > tkpack(label.widget, password.widget,ok) > tkwait.window(tt) > return(tclvalue(pass)) > }tkbind a function on the entry widget so that if <Return> is pressed it destroys the window: getPassword=function(){ require(tcltk) tt <- tktoplevel() pass=tclVar("") label.widget <- tklabel(tt, text="Enter Password") password.widget <- tkentry(tt,show="*",textvariable=pass) tkbind(password.widget,"<Return>",function(){tkdestroy(tt)}) ok <- tkbutton(tt,text="OK",default="active", command=function()tkdestroy(tt)) tkpack(label.widget, password.widget,ok) tkwait.window(tt) return(tclvalue(pass)) } How's that? See you in a few years... Barry
2008/8/11 Ben Bolker <bolker at zoology.ufl.edu>:> > I can set up an entry widget (thanks to an old > post by Barry Rowlingson) that gets a password and > exits when the user clicks on the "OK" button.Who? Oh dear, my past comes back to haunt me...> getPassword <- function(){ > require(tcltk) > tt <- tktoplevel() > pass=tclVar("") > label.widget <- tklabel(tt, text="Enter Password") > password.widget <- tkentry(tt,show="*",textvariable=pass) > ok <- tkbutton(tt,text="OK",default="active", > command=function()tkdestroy(tt)) > tkpack(label.widget, password.widget,ok) > tkwait.window(tt) > return(tclvalue(pass)) > }tkbind a function on the entry widget so that if <Return> is pressed it destroys the window: getPassword=function(){ require(tcltk) tt <- tktoplevel() pass=tclVar("") label.widget <- tklabel(tt, text="Enter Password") password.widget <- tkentry(tt,show="*",textvariable=pass) tkbind(password.widget,"<Return>",function(){tkdestroy(tt)}) ok <- tkbutton(tt,text="OK",default="active", command=function()tkdestroy(tt)) tkpack(label.widget, password.widget,ok) tkwait.window(tt) return(tclvalue(pass)) } How's that? See you in a few years... Barry