双R tcltk进度条

时间:2011-12-08 18:49:20

标签: r loops progress-bar

我的问题不是如何创建单个进度条,而是如何创建一个跟踪和更新两个不同进程的进度条。例如,在同一个窗口中,我想要一个条形码跟踪当前的模拟索引,另一个条形码跟踪另一系列数字...我当前的代码是:

library(tcltk2)

pb1 <- tkProgressBar(title = "Simulation Progress...", min = 1, max = 10, width = 300)
pb2 <- tkProgressBar(title = "Simulation Progress...", min = 2000, max = 2020, width = 300)

for (index in 1:10){

setTkProgressBar(pb1, index, label = paste("Index",index))

for (year in 2000:2020){

setTkProgressBar(pb2, year, label = paste("Year",year))

}

}

我想把两个酒吧放在一起,而不是分开......任何帮助都赞赏!

1 个答案:

答案 0 :(得分:4)

无法使用tkProgressBar,您必须深入了解tcltk的深度,如下所示:

library(tcltk2)

root <- tktoplevel()

l1 <- tk2label(root,"Simulation Progress...")
pb1 <- tk2progress(root, length = 300)
tkconfigure(pb1, value=0, maximum=9)

l2 <- tk2label(root, "Simulation Progress...")
pb2 <- tk2progress(root, length = 300)
tkconfigure(pb2, value=0, maximum=20, maximum = 20)

tkpack(l1)
tkpack(pb1)
tkpack(l2)
tkpack(pb2)

tcl("update")

for (index in 1:10){

    tkconfigure(l1, text = paste("Index", index))
    tkconfigure(pb1, value = index - 1)

    for (year in 2000:2020){
        tkconfigure(l2, text = paste("Year",year))
        tkconfigure(pb2, value = year - 2000)


    tcl("update")
    }       

}