[英]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.