Hi, I am working under Windows and I am using R2.11 I want to use tkscale in my GUI. As the interval is quite big, I can't set the scale to a certain specific value. Therefore I want to add tkentry to allow the user to set tkscale to a certain value. Here is the code library(tcltk) tt<-tktoplevel() tkpack(m1<-tkscale(tt,from=306870.00, to=3026741, label="alpha", variable="varalpha",showvalue=TRUE, resolution=1, orient="horiz"),side="bottom") tkpack(tkentry(tt,width="10",textvariable="varalpha",validate="key",validatecommand="string is double %P"),side="bottom") As you can see, varalpha is a global variable (I think in tcl, not in R), and if you change the parameter by the scale, the value in tkentry is updated. If I want to set now the value of varalpha by tkentry, it bugs. Does anyone have an idea, why? I already tried the interval from 0 to any number, which works fine... library(tcltk) tt<-tktoplevel() tkpack(m1<-tkscale(tt,from=0.00, to=1000, label="alpha", variable="varalpha",showvalue=TRUE, resolution=1, orient="horiz"),side="bottom") tkpack(tkentry(tt,width="10",textvariable="varalpha",validate="key",validatecommand="string is double %P"),side="bottom") Thanks in advance, Alexander -- View this message in context: http://r.789695.n4.nabble.com/set-tkscale-by-tkentry-tp4631174.html Sent from the R help mailing list archive at Nabble.com.
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. There may be a way to slow down the updates or validations so that you can edit the entry before the slider tries to validate and change the value. Or you can just include 0 as the minimum of the slider so that the intermediate values in the entry widget are in the allowable range. On Thu, May 24, 2012 at 2:20 AM, Alexander <juschitz_alexander at yahoo.de> wrote:> Hi, I am working under Windows and I am using R2.11 > I want to use tkscale in my GUI. As the interval is quite big, I can't set > the scale to a certain specific value. Therefore I want to add tkentry to > allow the user to set tkscale to a certain value. > > Here is the code > > library(tcltk) > > tt<-tktoplevel() > tkpack(m1<-tkscale(tt,from=306870.00, to=3026741, label="alpha", > variable="varalpha",showvalue=TRUE, resolution=1, > orient="horiz"),side="bottom") > tkpack(tkentry(tt,width="10",textvariable="varalpha",validate="key",validatecommand="string > is double %P"),side="bottom") > > As you can see, varalpha is a global variable (I think in tcl, not in R), > and if you change the parameter by the scale, the value in tkentry is > updated. If I want to set now the value of varalpha by tkentry, it bugs. > Does anyone have an idea, why? I already tried the interval from 0 to any > number, which works fine... > > library(tcltk) > > tt<-tktoplevel() > tkpack(m1<-tkscale(tt,from=0.00, to=1000, label="alpha", > variable="varalpha",showvalue=TRUE, resolution=1, > orient="horiz"),side="bottom") > tkpack(tkentry(tt,width="10",textvariable="varalpha",validate="key",validatecommand="string > is double %P"),side="bottom") > > Thanks in advance, > Alexander > > -- > View this message in context: http://r.789695.n4.nabble.com/set-tkscale-by-tkentry-tp4631174.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
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)
Hi Greg and jverzaniNWBKZ, thank you very much for your help. I already thought about your solution jverzaniNWBKZ. I hoped I could find a simpler solution (such as refering to the global variable of scale). As this is not possible for some intervals, I will take your solution. Thanks again for the quick answers!!! jverzaniNWBKZ wrote> > 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) > > ______________________________________________ > R-help@ mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- View this message in context: http://r.789695.n4.nabble.com/set-tkscale-by-tkentry-tp4631174p4631281.html Sent from the R help mailing list archive at Nabble.com.