set tkscale by tkentry
Greg Snow <538280 <at> gmail.com> writes:
I believe that what is happening is that when you try to edit the entry widget any intermediate values get sent to the slider widget which then checks to see if they are in the allowable range and if it is not then it sets the value to either the minimum and maximum and sends that back to the entry widget while you are still trying to edit it. Even if you highlight a single digit and try to replace it with a different digit it first deletes the highlighted digit resulting in a number smaller than the minimum of the slider which then updates the entry widget to the minimum before the new digit can go in, then adding the new digit makes it larger than the slider maximum.
Greg is right. You might try validating on focusout, rather than the key,
but this is easy enough to do in R code, rather than let tcl do that work:
a <- 306870; b <- 3026741
tt<-tktoplevel()
varalpha <- tclVar(a)
charalpha <- tclVar(as.character(a))
scale <- tkscale(tt, from=a, to=b, resolution=1, label="alpha",
variable=varalpha,
showvalue=TRUE, orient="horiz")
ed <- tkentry(tt, textvariable=charalpha)
tkpack(ed)
tkpack(scale)
## connect
tkconfigure(scale, command=function(...) {
tclvalue(charalpha) <- as.character(tclvalue(varalpha))
})
valid_input <- function(...) {
val <- as.numeric(tclvalue(charalpha))
if(a <= val & val <= b) {
message("set to ", val)
tclvalue(varalpha) <- val
} else {
message("not valid...")
tkfocus(ed)
}
}
tkbind(ed, "<Return>", valid_input)
tkbind(ed, "<FocusOut>", valid_input)