繁体   English   中英

“ R” tcltk2中的Spinbox

[英]Spinbox in “R” tcltk2

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

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

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

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM