2

My question here is not how to create a single progress bar, but instead how to create a progress bar that keeps track and updates two different processes. For example within the same window I'd like to have a bar keeping track of the current simulation index and another bar keeping track of another series of numbers...my current code is:

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))

}

}

I'd like to have both bars together, not separate...any help appreciated!

Francesco
  • 819
  • 1
  • 7
  • 7

1 Answers1

4

Not possible using tkProgressBar, you'll have to dig down into the depth of tcltk, something like this:

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")
    }       

}
themel
  • 8,825
  • 2
  • 32
  • 31
  • A couple of questions: why do you need to use tcl("update") and why do you use value = 0, maximum =0 and value = 0, maximum =20 inside the 2 tkconfigure(...)? Thanks for your help! – Francesco Dec 08 '11 at 19:40
  • those look like typos to me. I would try out the code yourself, not being afraid to experiment. You'll be able to tell pretty quickly whether it works as you'd like. – Ben Bolker Dec 08 '11 at 20:07
  • The 0 was indeed a typo, should be a 9 - this is slightly different from your code since tk2progress doesn't have min/max concept, just a range from 0 to max. tcl("update") is used to force the screen to update, see here: http://www2.tcl.tk/1252 – themel Dec 08 '11 at 20:54
  • Hey guys, what if, instead, within the second progress bar I want to see the progress going from min to max and then once it changes to the secon year (e.g. 2001) see the same progress from min to max...sort of keeping track within each year at what stage I am...any help? – Francesco Dec 09 '11 at 20:01