2016-11-12 53 views
1
`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))以自动运行?如何为gWidget提供功能以及如何利用用户输入到'gedit'中的输入?

编辑:在回复帖子我设法工作的功能,谢谢。 如何在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))) 
     }) 
}) 

回答

0

只需添加一个处理程序:

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 = "") 
} 
相关问题