# NOT RUN {
tt <- tktoplevel()
tt <- tkRplot(tt, function () plot(1:10))
FUN <- local({
canPos <-.Tcl(paste(tt$env$canvas, "create text 0 0 "))
function (x, y) {
x <- as.numeric(x)
y <- as.numeric(y)
tkdelete(tt$env$canvas, tclvalue(canPos))
xy <- formatC(tk2usr(x, y),
digits = 2,
format = "f",
width = 5)
canPos <<- .Tcl(
paste(tt$env$canvas, "create text 40 10 -fill blue -justify left -text { ",
xy[1], " ", xy[2],
"} -font {Helvetica -10}"))
}})
tkbind(tt$env$canvas, "<Motion>", FUN)
tkbind(tt$env$canvas, "<Motion>") #to give current bidings
FUN1 <- function (x,y) print(tk2usr(x,y))
addTkBind(tt$env$canvas, "<Motion>", FUN1)
tkbind(tt$env$canvas, "<Motion>") #to give current bidings
# }
Run the code above in your browser using DataLab