title: TkInter: how to wait until callback from after method has completed
body: <p>When using the Tkinter .after method, the code continues passed without waiting for the callback to complete.</p>
  
  <pre><code>import tkinter as tk
  import tkinter.ttk as ttk
  import time
  from datetime import datetime
  
  global i
  i = 0
  global j
  j = 0
  
  def SomeFunction():
      global i
      for num in range(10):
          i+=1
          x = barVar.get()
          barVar.set(x+5)
          histrun_mainWindow.update()
          time.sleep(2)
  
  def SecondFunction():
      global j
      for num in range(10):
          j+=1
          x = barVar.get()
          barVar.set(x+5)
          histrun_mainWindow.update()
          time.sleep(2)
  
  def Load(run_date):
      histrun_mainWindow.after(50, SomeFunction)
      histrun_mainWindow.after(50, SecondFunction)
      global i, j 
      print 'Number is :', i + j
  
  histrun_mainWindow = tk.Tk()
  run_date = datetime.today().date()
  barVar = tk.DoubleVar()
  barVar.set(0)
  bar = ttk.Progressbar(histrun_mainWindow, length=200, style='black.Horizontal.TProgressbar', variable=barVar, mode='determinate')
  bar.grid(row=1, column=0)
  button= tk.Button(histrun_mainWindow, text='Run for this date ' + str(run_date), command=lambda:Load(run_date))
  button.grid(row=0, column=0)
  histrun_mainWindow.mainloop()
  </code></pre>
  
  <p>This example shows what is happening. The .after() calls the Load() function but doesn't wait for Load() to complete, it goes straight on to the next line. </p>
  
  <p>I want i to print as 10 but because the .after() doesn't wait for Load() to finish it's additions, i prints as 0</p>
  
  <p>The progress bar continues to update so I know that Load was called as it continues in the background after i is printed </p>