0

我通过“tcltk2”库在“R”GUI中创建了一个旋转框

   my_ratio <- tk2spinbox(my_window, from = 1, to = 10, increment = 1)

如何将选择的值赋予“R”数字变量?

4

1 回答 1

0

tcltk2的作者 Philippe Grosjean用下面的代码片段轻轻地向我展示了如何做到这一点:

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)
于 2017-11-24T16:00:47.977 回答