2016-11-12 92 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 = "") 
} 
相關問題