Skip to content
Prev 152893 / 398500 Next

tkentry that exits after RETURN?

2008/8/11 Ben Bolker <bolker at zoology.ufl.edu>:
Who? Oh dear, my past comes back to haunt me...
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