[R] MENU TCL-TK

Gabor Grothendieck ggrothendieck at gmail.com
Tue Mar 18 20:37:30 CET 2008


Make sure d has been created (see first line marked ##) and then
use d <<- function(a, b) as shown in second line marked ##.
See ?"<<-"

Another solution is to use the proto package.   The home
page
    http://rproto.googlecode.com
has pointers to examples of using gWidgets with proto and
the same idea would apply to tcltk or any GUI with callbacks.

Just plain environments would work too (in fact proto objects
are environments).

Here is function3 redone:

function3<-function(a,b){
    require(tcltk)
    d <- 0 ##
    tt <- tktoplevel()
    topMenu <- tkmenu(tt)
    tkconfigure(tt,menu=topMenu)
    fileMenu <- tkmenu(topMenu,tearoff=FALSE)
    openRecentMenu <- tkmenu(topMenu,tearoff=FALSE)
    tkadd(openRecentMenu,"command",label="Function1",
       command=function() d <<- function1(a,b)) ##
    tkadd(openRecentMenu,"command",label="Function2",
           command=function() function2(d))
    tkadd(fileMenu,"cascade",label="Functions",menu=openRecentMenu)
    tkadd(fileMenu,"command",label="Quit",command=function() tkdestroy(tt))
    tkadd(topMenu,"cascade",label="File",menu=fileMenu)
    tkfocus(tt)
}



On Tue, Mar 18, 2008 at 3:23 PM, ermimi <ermimi_ at hotmail.com> wrote:
>
> Hello!
>
> I need help in a menu in TCL-TK. I have 3 functions, one function
> (function1) that sum 2 numbers and return the result. Other
> function(function2) that print a number. And the other (function3), is a
> menu that has several options. I need use the result that returns the option
> that calls to function1 to call the function2.
>
> tkadd(openRecentMenu,"command",label="Function1",
>    command=function() function1(a,b))
>
>
> tkadd(openRecentMenu,"command",label="Function2",
>        command=function() function2(d))
>
> I want that the value "d" is the return value of the function1, but I don´t
> know as I can asign the value to "d"
>
> Next, I show the 3 functions.
>
> Thank you very much,
>
> A greetings
>
> function1<-function(a,b){
>        return(a+b);
>        }
>
> function2<-function(a){
>        print(a);
>        }
>
> function3<-function(a,b){
> require(tcltk)
> tt <- tktoplevel()
> topMenu <- tkmenu(tt)
> tkconfigure(tt,menu=topMenu)
> fileMenu <- tkmenu(topMenu,tearoff=FALSE)
> openRecentMenu <- tkmenu(topMenu,tearoff=FALSE)
> tkadd(openRecentMenu,"command",label="Function1",
>    command=function() function1(a,b))
> tkadd(openRecentMenu,"command",label="Function2",
>        command=function() function2(d))
> tkadd(fileMenu,"cascade",label="Functions",menu=openRecentMenu)
> tkadd(fileMenu,"command",label="Quit",command=function() tkdestroy(tt))
> tkadd(topMenu,"cascade",label="File",menu=fileMenu)
> tkfocus(tt)
> }
> --
> View this message in context: http://www.nabble.com/MENU-TCL-TK-tp16128790p16128790.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list