问题
I am trying to create a interface where the user can key in a number for the script to run. However, I am unable to retrieve the value keyed into gedit. Can anyone help me? Here's what I have done:
require(gWidgets2RGtk2) #Load package
w=gbasicdialog("key number")
a<-gedit("1",cont=w,handler=function(h,...){number<-svalue(a)})
visible(w)=TRUE
回答1:
Here I create , 2 gedit and update the value of one with the other value using a button:
w <- gwindow("test")
g <- ggroup(cont=w, horizontal=FALSE)
x <- gedit("20",cont=g)
gbutton("changevalue",cont=g,handler=function(h,...) {
svalue(e) <- svalue(x)
})
e <- gedit("", cont=g)
回答2:
What I have done here is the same as suggested by jverzani
require(gWidgets2RGtk2) #Load package
w = gbasicdialog("key number")
a <- gedit("1",cont=w)
addHandlerKeystroke(a, handler=function(h,..) {
number <- svalue(a)
print(number)
})
visible(w)=TRUE
来源:https://stackoverflow.com/questions/21252493/extracing-values-of-gedit-in-gbasicdialog