您如何为 gWidget 提供功能以及如何利用用户输入 'gedit'?

How do you give functionality to a gWidget and how to utilise the input by a user into 'gedit'?

`win <- gwindow(title = "Analysing PDB structures", visible=TRUE, name=title,
           width = NULL, height = NULL, parent=NULL)
group <- ggroup(horizontal = FALSE, container=win)
obj <- glabel("Type your PDB code here:", container = group)
obj <- gedit("", container=group)
obj <- gbutton("Go", container = group)`

当用户在gedit中输入一个值并按下gbutton "Go"时,如何让后续代码(例如install.packages(bio3d))自动运行?

编辑:作为对 post 的回应,我已经设法实现了该功能,谢谢。 如何在 obj3 中的 obj2 中利用用户在 'gedit' 中给出的输入?我究竟做错了什么?

win <- gwindow(title = "Analysing PDB structures", 
           visible=TRUE, name=title,
           width = NULL, height = NULL, parent=NULL)
group <- ggroup(horizontal = FALSE, container=win)
obj1 <- glabel("Type your PDB code here:", container = group)
innergroup <- ggroup(container = group)
obj2 <- gedit((file1<-""), container=innergroup)
obj3<-addHandlerChanged(obj2, handler=function(...){
  gbutton( "Go", container = innergroup, 
       handler = function( h, ... ) {
         gmessage( svalue( obj2 ), title = (pdb<- read.pdb(file1)))
       } )
 })

只需添加一个处理程序:

win <- gwindow( title = "Analysing PDB structures", 
                visible=TRUE, name=title,
                width = NULL, height = NULL, parent=NULL)
group <- ggroup( horizontal = FALSE, container=win )
obj1 <- glabel( "Type your PDB code here:", container = group )
obj2 <- gedit( "", container = group )
obj3 <- gbutton( "Go", container = group, 
                handler = function( h, ... ) {
    gmessage( svalue( obj2 ), title = "" )
} )

将您的代码放在 gmessage() 中,或者在之前定义您的函数并按名称引用它:handler = foo。该函数必须按照以下模式定义:

foo <- function( h, ... )
{ 
    gmessage( svalue( obj2 ), title = "" )
}