[R] Some R-Tcl/Tk-BWidget newbie questions.

JeeBee JeeBee at troefpunt.nl
Wed Jun 21 23:52:52 CEST 2006


Dear list,

Could somebody who is more experienced with the Tcl/Tk interface from R
please help me clarify the issues I've put below with ### --> tags?

Several things go wrong, and it's probably because of messy code, but I
have a difficult time finding out what is the cause.

Thanks very much,
JeeBee.


require(tcltk) || stop("Package tcltk is not available.")
# Add path to BWidgets
addTclPath(".")
version.BWidget <<- tclvalue(tclRequire("BWidget"))

start.gui <- function() {
  # Toplevel
  tt <- tktoplevel()
  tkwm.title(tt, "MyTitle")

  # Notebook
### --> The following line makes R hang with 100% cpu forever
  #tkpack(tn <- tkwidget(tt, "NoteBook"), fill="both", expand=TRUE)
### --> This works, but not sticky="news",
### --> the notebook does not resize together with the window
  tn <- tkwidget(tt, "NoteBook")
  tkgrid(tn, sticky="news")

### --> I guess there is a simpler way to do this ...
  tbn <- tclvalue(tkinsert(tn, "end", "Algemeen", "-text", "Algemeen"))
  tkpack(tbw.algemeen <- .Tk.newwin(tbn))
  tkpack(tab.algemeen <- tkframe(tbw.algemeen))
  tbn <- tclvalue(tkinsert(tn, "end", "Relaties", "-text", "Relaties"))
  tkpack(tbw.relaties <- .Tk.newwin(tbn))
  tkpack(tab.relaties <- tkframe(tbw.relaties))
  tbn <- tclvalue(tkinsert(tn, "end", "Posten", "-text", "Posten"))
  tkpack(tbw.posten <- .Tk.newwin(tbn))
  tkpack(tab.posten <- tkframe(tbw.posten))
  tbn <- tclvalue(tkinsert(tn, "end", "Instellingen", "-text", "Instellingen"))
  tkpack(tbw.instellingen <- .Tk.newwin(tbn))
  tkpack(tab.instellingen <- tkframe(tbw.instellingen))

  gui.maak.tab(tab.algemeen)
  gui.maak.tab(tab.relaties)
  gui.maak.tab(tab.posten)
  gui.maak.tab(tab.instellingen)

  tkgrid(tkbutton(tt, text="GUI bijwerken", 
    command=function() verwerk.button("GUIBijwerken", tt)))

  # FIXME: add cleanup handler?
  #tkbind(tt, "<Destroy>", function() tkdestroy(tn))

### --> Don't understand this ... if I do the last "raise" only,
### --> then I see all tabs in the first tab, until I go to another
### --> tab and back. With all these "raises", it works
  tcl(tn, "raise", "Instellingen")
  tcl(tn, "raise", "Posten")
  tcl(tn, "raise", "Relaties")
  tcl(tn, "raise", "Algemeen")
}

gui.maak.tab <- function(tt) {
  tkgrid(tklabel(tt, text="Instellingen"), sticky="news")
  test.button <- tclVar("one two") 
  tkgrid(tkcheckbutton(tt,variable=test.button))
}



More information about the R-help mailing list