The following R code maps the OK button of a simple toplevel window to a function which displays a message box.
require(tcltk)
PressedOK <- function()
{
tkmessageBox(message="You pressed OK!")
}
tt <- tktoplevel()
OK.but <- tkbutton(tt,text="OK",command=PressedOK)
tkgrid(OK.but)
tkfocus(tt)
The toplevel window is shown below. We have not given it a title (using tkwm.title), so the title bar displays the Tcl ID for this window, which is 1 in this case.

The result of pressing OK is shown below:
