[英]Spinbox in “R” tcltk2
I created a spinbox in a "R" GUI by means of the "tcltk2" library 我通过“ tcltk2”库在“ R” GUI中创建了一个旋转框
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? 如何将选择的值赋予“ R”数字变量?
Philippe Grosjean, the author of tcltk2 , gently showed me how to do it with the following snippet: 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.