I created a spinbox in a "R" GUI by means of the "tcltk2" library
my_ratio <- tk2spinbox(my_window, from = 1, to = 10, increment = 1)
How can I give the value of the selection to a "R" numeric variable?
I created a spinbox in a "R" GUI by means of the "tcltk2" library
my_ratio <- tk2spinbox(my_window, from = 1, to = 10, increment = 1)
How can I give the value of the selection to a "R" numeric variable?
Philippe Grosjean, the author of tcltk2, gently showed me how to do it with the following snippet:
library(tcltk2)
my_window <- tktoplevel()
spin_value <- tclVar(3)
my_ratio <- tk2spinbox(my_window, from = 1, to = 10, increment = 0.1, textvariable = spin_value, format = "%5.1f", width = 10)
tkgrid(tk2label(my_window, text = "Ratio:"), my_ratio, padx = 10, pady = c(10, 5))
on_ok <- function() {
val <- as.numeric(tclvalue(spin_value))
tkdestroy(my_window)
cat("The ratio is:", val, "\n")
}
my_but_ok <- tk2button(my_window, text = "OK", width = -6, command = on_ok)
tkgrid(my_but_ok, columnspan = 2, padx = 10, pady = c(5, 15))
tkfocus(my_window)