2

My program contains a main window in which I would like to display a progress bar. I use tcltk and R.

The following code shows how to display a progress bar in a new popped-up window, that is not what I want to do : I want it to be inside a window I precedently created.

pb <- tkProgressBar("test progress bar", "Some information in %",0, 100, 50)
Sys.sleep(0.5)
u <- c(0, sort(runif(20, 0, 100)), 100)
for(i in u) {
    Sys.sleep(0.1)
    info <- sprintf("%d%% done", round(i))
    setTkProgressBar(pb, i, sprintf("test (%s)", info), info)
}
Sys.sleep(5)
close(pb)

I've no idea how to insert it in my window.

Thank you

David
  • 4,785
  • 7
  • 39
  • 63
  • What you want is not clear enough, show some code or at least describe what you've done already to give people more color save them all the work of redoing what you've done – statquant Jul 24 '13 at 07:06

1 Answers1

2

This is pretty much lifted from this answer. The gist is that tkProgressBar won't get you what you want. Instead, there's the function tk2progress in the tcltk2 package. Using that function, you can create a widget that you can place in a window.

root <- tktoplevel()

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

tkgrid(l1, row = 0)
tkgrid(pb1, row = 1)

for (index in 1:10){

    tkconfigure(l1, text = paste("Index", index))
    tkconfigure(pb1, value = index - 1)
    Sys.sleep(1)
}
Community
  • 1
  • 1
BenBarnes
  • 19,114
  • 6
  • 56
  • 74