Focusing a Window in R TclTk

The following example makes window tt the active window. This won't work when run from RGui in Windows, because the focus will automatically return to RGui. But it will work when run from a script file, using Rterm < scriptfile.R > scriptfile.Rout.

tt <- tktoplevel()
tkfocus(tt)

The window shown below is focused:



The window shown below is unfocused: