The following example illustrates the use of a checkbox in a tk toplevel window. The value of the checkbox is mapped to a Tcl variable called cbValue, which is initialized to zero (i.e. the checkbox will be initially unchecked). The OnOK function triggered by the OK button captures the value of the Tcl variable mapped to the checkbox (cbValue) before destroying the window. Then it displays an appropriate message box depending on the value of the checkbox.
require(tcltk)
tt <- tktoplevel()
cb <- tkcheckbutton(tt)
cbValue <- tclVar("0")
tkconfigure(cb,variable=cbValue)
tkgrid(tklabel(tt,text="I like R TclTk "),cb)
OnOK <- function()
{
cbVal <- as.character(tclvalue(cbValue))
tkdestroy(tt)
if (cbVal=="1")
tkmessageBox(message="So do I!")
if (cbVal=="0")
tkmessageBox(message="You forgot to check the box to say that you like R TclTk!",icon="warning")
}
OK.but <- tkbutton(tt,text="OK",command=OnOK)
tkgrid(OK.but)
tkfocus(tt)



