Re: [R] MENU TCL-TK

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 18 Mar 2008 15:37:30 -0400

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.
>



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. Received on Tue 18 Mar 2008 - 19:40:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 18 Mar 2008 - 20:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive