[问题] GUI回传变量

楼主: TOOYA (在草地等流星)   2019-04-30 15:47:54
我想做一个视窗选项,
https://i.imgur.com/7YY1QOw.jpg
让使用者可以从“建模”“校正”“分析”三个选项中做选择
我将
“建模”命名为1
“校正”命名为2
“分析”命名为3
我希望能够回传这个视窗选择后的资讯(1/2/3),
但是我看了tcltk2的范例,大部分的反应都只是关掉视窗...
最多是根据选择做一件简单的反应,
例如使用switch+tkmessageBox开新视窗显示一句话。
不知道要怎么做,才能够把选择的结果纪录回传,
方便我做后续的处理?
(print不行,我要存成变量,不是印出来)
想了一天想不出来,来向各位大神求救><
TEST_GUI = function(){
library(tcltk2)
win1 <- tktoplevel()
win1$env$rb1 <- tk2radiobutton(win1)
win1$env$rb2 <- tk2radiobutton(win1)
win1$env$rb3 <- tk2radiobutton(win1)
rbValue <- tclVar("PANDA")
tkconfigure(win1$env$rb1, variable = rbValue, value = 1)
tkconfigure(win1$env$rb2, variable = rbValue, value = 2)
tkconfigure(win1$env$rb3, variable = rbValue, value = 3)
tkgrid(tk2label(win1, text = "现在要执行的功能?"), columnspan = 2, padx = 10,
pady = c(10, 5))
tkgrid(tk2label(win1, text = "建模"), win1$env$rb1, padx = 10, pady = c(0, 5))
tkgrid(tk2label(win1, text = "校正"), win1$env$rb2, padx = 10, pady = c(0, 5))
tkgrid(tk2label(win1, text = "分析"), win1$env$rb3, padx = 10, pady = c(0, 5))
onOK <- function() {
rbVal <- as.character(tclvalue(rbValue))
tkdestroy(win1)
return(rbVal) #无效
}
win1$env$butOK <- tk2button(win1, text = "OK", width = -6, command = onOK)
tkgrid(win1$env$butOK, columnspan = 2, padx = 10, pady = c(5, 15))
tkfocus(win1)
}
楼主: TOOYA (在草地等流星)   2019-05-01 10:25:00
太太太感谢了,晚一点进公司试试看!昨天下班前有发现<<-这个指令,下班后还在想要怎么应用~
作者: andrew43 (讨厌有好心推文后删文者)   2019-05-01 09:03:00
https://pastebin.com/yp9B0B1v 改动处已留comment

Links booklink

Contact Us: admin [ a t ] ucptt.com