title: Tck after command, vwait, and the event loop
body: <p>My Tk app has many "wait" windows or pauses in a functions that allow time for other backgrounds commands to do their job. The problem is that using "after 5000" within a function disables all the buttons in the application. I've found a lot of information, the most helpful was at <a href="http://wiki.tcl.tk/808" rel="nofollow">http://wiki.tcl.tk/808</a>. First lesson learned is that "after" without a script won't process the event loop, and second is that vwaits are nested. </p>
  
  <p>So, I use the following simple "pause" function in place of "after":</p>
  
  <pre><code>proc pause {ms {waitvar WAITVAR}} {
     global $waitvar
     after $ms "set $waitvar 1"
     puts "waiting $ms for $waitvar"
     vwait $waitvar
     puts "pause $ms returned"
  }
  
  button .b -text PressMe -command {pause 5000 but[incr i]}; # everyone waits on this
  pack .b
  after 0 {pause 1000 var1}; pause 3000 var2; # works as expected
  after 0 {pause 3000 var3}; pause 1000 var4; # both return after 3 secs
  </code></pre>
  
  <p>My button is always responsive, but if pressed, all other vwaits are held up for at least another 5 seconds. And a second press within 5 seconds also delays the first one. Understanding that vwaits are nested, this is now expected and not really problematic.</p>
  
  <p>This seems almost too simple a solution, so I'd like to get comments as to what issues I might not have though of.</p>