Posted to tcl by jdc at Wed Aug 08 06:32:00 GMT 2012view raw

  1. package require Tk
  2.  
  3. proc timer {widget seconds} {
  4. toplevel $widget
  5. ttk::progressbar $widget.pb1 -orient horizontal -mode determinate -maximum $seconds
  6. grid $widget.pb1
  7. update idletasks
  8.  
  9. # Do some real work here for $seconds seconds
  10. for {set i 0} {$i < $seconds} {incr i} {
  11. after 1000 ;# Just waiting in this example, might as well do something useful here
  12. $widget.pb1 step ;# After some part of the work, advance the progressbar
  13. update idletasks;# Needed to update the progressbar
  14. }
  15.  
  16. # Done, clean up the dialog and progressbar
  17. destroy $widget
  18. }
  19.  
  20. pack [button .b1 -text "Upgrade" -command { timer .new 10 }]