This example shows a scrollable frame (from the BWidget package). This is useful if
you have an unknown number of entry widgets on a dialog and you don't know whether they will fit in
a normal-sized dialog.
The BWidget package is not included in the minimal installation of Tcl/Tk
which comes with R. They are available within the ActiveTcl distribution, available from
here. To use these additional Tcl/Tk packages,
you need to set the environment variable TCL_LIBRARY to your Tcl library path, e.g. C:\Tcl\lib\tcl8.4 and
set the environment variable MY_TCLTK to a non-empty string, e.g. "Yes". You may also need to use
addTclPath("C:/Tcl/lib") (in R) to tell Tcl/Tk where to find these additional packages.
require(tcltk)
tclRequire("BWidget")
tt <- tktoplevel()
tkpack(tklabel(tt,text="This is not part of the scrollable frame"))
sw <- tkwidget(tt,"ScrolledWindow",relief="sunken",borderwidth=2)
sf <- tkwidget(sw,"ScrollableFrame")
tkcmd(sw,"setwidget",sf)
subfID <- tclvalue(tkcmd(sf,"getframe"))
lab <- tkcmd("label",paste(subfID,".lab",sep=""),text="This is a Scrollable Frame")
tkpack(lab)
entryList <- list()
for (i in (1:20))
{
entryList[[i]] <- tkcmd("entry",paste(subfID,".",i,sep=""),width=50)
tkpack(entryList[[i]],fill="x",pady=4)
tkbind(entryList[[i]],"<FocusIn>",function() tkcmd(sf,"see",entryList[[i]]))
tkinsert(entryList[[i]],"end",paste("Text field",i))
}
tkpack(sw,fill="both",expand="yes")
The R code above produces the following Tk window:
Scrolling down reaveals: