[R-gui] MainFrame Tk BWidget
James Wettenhall
wettenhall at wehi.edu.au
Tue Apr 20 16:34:31 CEST 2004
Enrique,
Have a look at the BWidget demos that come with ActiveTcl.
For your amusement, here are my efforts to totally confuse
myself about the MainFrame widget. Does it require "." as a
parent? What difference does having a menu make?
Three cases below.
(1) A MainFrame widget with no menu and with parent tt
(2) A MainFrame widget with a menu and with parent tt
(3) A MainFrame widget with a menu and with parent .
(1) A MainFrame widget with no menu and with parent tt
library(tcltk)
tt <- tktoplevel()
tclRequire("BWidget")
mainFrame <- tkwidget(tt,"MainFrame")
tkdestroy(mainFrame) # Optional
tkdestroy(tt)
# Notes: No problems with Case (1). :)
(2) A MainFrame widget with a menu and with parent tt
library(tcltk)
tt <- tktoplevel()
tclRequire("BWidget")
exit <- function()
{
tkdestroy(mainFrame)
tkdestroy(tt)
}
mainMenu <-
paste("\"&File\" all file 0 ",
"{{command \"E&xit\" {} \"Exit Case 2\" {}",
"-command \"",.Tcl.callback(exit),"\"}}")
mainFrame <- tkwidget(tt,"MainFrame",menu=mainMenu)
tkpack(mainFrame)
# Notes: Now I can crash my R session by typing
# either of tkdestroy(tt) or tkdestroy(mainFrame)
# or clicking "Exit" in the File menu.
# The following DOESN'T crash my R session and
# appears to destroy the menu (and frame?):
tkcmd("MainFrame::_destroy",mainFrame)
# But then tkdestroy(tt) still crashes my R session.
# Now if instead of tkdestroy(tt), I click on the
# close button at the top-right-hand corner of tt,
# (after doing MainFrame::_destroy), I get this:
Application Error
Error: can't read "_widget(.1.1,top)": no such element in array
can't read "_widget(.1.1,top)": no such element in array
can't read "_widget(.1.1,top)": no such element in array
while executing
"$_widget($path,top) configure -menu {}"
(procedure "MainFrame::_destroy" line 6)
invoked from within
"MainFrame::_destroy .1.1"
(command bound to event)
# Note that the menu option of BWidget::MainFrame is described
# as "read-only". Is that a clue?
(3) A MainFrame widget with a menu and with parent .
library(tcltk)
tkwm.deiconify(".")
tclRequire("BWidget")
exit <- function()
{
tkcmd("MainFrame::_destroy",mainFrame)
tkwm.withdraw(".")
}
mainMenu <-
paste("\"&File\" all file 0 ",
"{{command \"E&xit\" {} \"Exit Case 3\" {}",
"-command \"",.Tcl.callback(exit),"\"}}")
mainFrame <- tkwidget(.TkRoot,"MainFrame",menu=mainMenu)
tkpack(mainFrame)
# Notes: Using the Tk root window "." is ugly
# because if you destroy it then I think you have to
# restart R or at least reload the tcltk package. The
# exit function used here simply hides the "."
# window. It doesn't really destroy anything.
Well, maybe that will give others some clues in order to
go further...
Regards,
James
More information about the R-SIG-GUI
mailing list