[R] R tcl/tk

Charles Annis, P.E. Charles.Annis at StatisticalEngineering.com
Mon Oct 23 14:31:53 CEST 2006


Peter:

Thank you for your response.  I apologize for not sending a reproducible
example.  I have attached a reproducible example of the problem here.  This
is a much abbreviated version of my problem and even so it's rather long for
an example.  Run with 

tcl.tk.example(PROBLEM = TRUE)
tcl.tk.example(PROBLEM = FALSE)

to turn the problem on and off.

I have also attached a tcl.tk.example.txt file since these long inclusions
within an R-help note often have the line feeds missing.

Thank you for your insights.

Charles Annis, P.E.
###########################


tcl.tk.example <- function(PROBLEM = TRUE) {
require(tcltk)
t2 <<- tktoplevel()

tktitle(t2) <- "Hit/Miss"
group.button1 <<- tkradiobutton(t2)
group.button2 <<- tkradiobutton(t2)

repeated.measures.value <- tclVar("3")
l.repeated.measures.value <- tklabel(t2, text="   hit/miss column(s) ")
e.repeated.measures.value <- tkentry(t2,
textvariable=repeated.measures.value, width=5, borderwidth = 3,
relief="sunken")

tkgrid(tklabel(t2, text="Hit/Miss POD Setup"), columnspan=2, sticky="n")

tkgrid.configure(l.repeated.measures.value, e.repeated.measures.value,
sticky="e")
tkgrid.configure(e.repeated.measures.value, sticky="w", padx=5)

############################################################################
####
frame.2 <- tkframe(t2, borderwidth = 3, width=150, height=100,
relief="ridge")
GROUP.column.value <- tclVar("4") 
l.GROUP.column.value <- tklabel(frame.2, text="GROUP column ")
e.GROUP.column.value <- tkentry(frame.2, textvariable=GROUP.column.value,
width=2, borderwidth = 3, relief="sunken")
l.group.value.yes <- tklabel(frame.2, text="group data?    yes ")
l.group.value.no <- tklabel(frame.2, text="NO ")
group.buttonValue <- tclVar("GROUP.DATA")
tkconfigure(group.button1, variable=group.buttonValue, value="TRUE")
tkconfigure(group.button2, variable=group.buttonValue, value="FALSE")
if(PROBLEM){
### group.button1 not placed within frame.2 because I don't know how to
indicate frame.2
tkgrid(l.group.value.yes, group.button1, sticky="e")
tkgrid(group.button1, sticky="w")
tkgrid(l.group.value.no, group.button2, sticky="e")
tkgrid(group.button2, sticky="w") } else {
### second dummy lable is correctly placed because I can tell it that it
belongs in frame.2
tkgrid(l.group.value.yes, tklabel(frame.2, text="dummy"), sticky="e")
tkgrid(l.group.value.no, tklabel(frame.2, text="dummy"), sticky="e")
}
tkgrid(l.GROUP.column.value, e.GROUP.column.value,  sticky="e")
tkgrid(e.GROUP.column.value,  sticky="w", padx=5, pady=5)
tkgrid(frame.2, columnspan=2)
############################################################################
####
OnOK <- function()
{
    hit.miss.columns <<- eval(parse(text=paste("c(", substr(gsub(pattern =
"-", replacement=":",
as.character(tclvalue(repeated.measures.value))),start=1,stop=10000), ")")))
    n.columns <<- length(hit.miss.columns)
    GROUP.column     <<-
as.double(as.character(tclvalue(GROUP.column.value)))
    repeated.measures.GROUP.names   <<-
as.character(tclvalue(repeated.measures.GROUP.value))

###read.hit.miss.input()    
    tkdestroy(t2)
}
OK.but <- tkbutton(t2,text=" OK ", command=OnOK, borderwidth = 3,
relief="raised")
tkgrid(tklabel(t2,text="      Must click OK\nto register changes.  "),
(OK.but), sticky="e")
tkgrid(OK.but, sticky="w")
tkfocus(t2)
}
tcl.tk.example(PROBLEM = TRUE)
tcl.tk.example(PROBLEM = FALSE)

######################################################################



Charles Annis, P.E.

Charles.Annis at StatisticalEngineering.com
phone: 561-352-9699
eFax:  614-455-3265
http://www.StatisticalEngineering.com
 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Peter Dalgaard
Sent: Monday, October 23, 2006 3:35 AM
To: Charles.Annis at statisticalengineering.com
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] R tcl/tk

"Charles Annis, P.E." <Charles.Annis at statisticalengineering.com> writes:

> Friends:
> 
> I am a long-time R user, learning tcl/tk, and am tying myself in knots
over
> something that should be simple.
>   
> I want to create a frame and put that frame inside the toplevel frame.
> 
> This works (i.e. it places text in col 1, and the corresponding entry box
in
> column 2) and later frame.2 resides where it should in the toplevel frame.
> 
> tkgrid(tklabel(frame.2, text="FACTOR column "), tkentry(frame.2,
> textvariable=FACTOR.column.value, width=2),  sticky="e")
> 
> 
> This doesn't work because I don't know how to tell tcl that answer.button1
> belongs in frame2:
> 
> tkconfigure(answer.button1, variable=buttonValue, value="TRUE")
> 
> tkgrid(tklabel(frame.2, text="Question?    yes "), answer.button1,
> sticky="e")
>                                                   ^^^^^^^^^^^^^^^
> 
> I know this can not be as hard as I am making it.

Possibly, but there seems to be some context missing, so I can't quite
grasp what you want to do. It does look a bit suspicious that you
aren't saving the objects generated by tklabel and tkentry though.

In general, the hierarchy between widgets is defined at widget
creation time, so why is there no 

answer.button1 <- tkbutton(frame.2,..whatever..) 

?
-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help at stat.math.ethz.ch 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.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: tcl.tk.example.txt
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20061023/58a17a42/attachment.txt 


More information about the R-help mailing list