I have a script along the lines of:
if (!require(tcltk2)) {install.packages('tcltk2', repos="http://cran.us.r-project.org"); require(tcltk2)}
base <- NULL
done <- tclVar(0)
quasitelgui <- function(inputfile = NULL)
{
base <- tktoplevel()
tkwm.title(base, "QuasiTel")
# Files
file.frm <- tkframe(base, borderwidth=2)
datafile.lbl <- tklabel(file.frm, text="Data")
datafile.entry <- tkentry(file.frm, state="readonly")
datafile.btn <- tkbutton(file.frm, text="Browse...")
tkgrid(datafile.lbl, datafile.entry, datafile.btn)
tkgrid.configure(datafile.lbl, sticky="e")
tkgrid.configure(datafile.entry, sticky="ew", padx=1)
tkgrid.columnconfigure(file.frm, 1, weight=1)
tkgrid(file.frm)
tkgrid.configure(file.frm, sticky="ew")
# Main
main.frm <- tkframe(base, borderwidth=2)
g1.lbl <- tklabel(main.frm, text="Group 1")
g2.lbl <- tklabel(main.frm, text="Group 2")
tkgrid(g1.lbl, g2.lbl)
q.btn <- tkbutton(bott.frm, text="Quit", command=function() tclvalue(done) <- 1)
tkbind(base,"<Destroy>", function() tclvalue(done) <- 2)
tkgrid(filter.lbl, columnspan=2)
tkgrid(filter.entry)
tkgrid(ok.btn, q.btn)
tkgrid.configure(ok.btn, q.btn, padx=1)
tkgrid(bott.frm)
tkgrid.columnconfigure(base, 0, weight=1)
if (length(inputfile) > 0) { datafile.open(inputfile) }
}
cmd.args <- commandArgs(trailingOnly=TRUE)
if (length(cmd.args) > 0) {
quasitelgui(gsub("\\\\", "/", cmd.args[1]))
} else {
quasitelgui()
}
tkfocus(base)
tkwait.variable(done)
tkdestroy(base)
I'm running it via rscript from another GUI. I want the window to grab focus when it starts. Tkfocus doesn't do it.