title: Tkinter after_cancel in python
body: <p>The attached code randomly draws squares on the canvas using the "after" method. I expected to stop the drawing when I clicked the mouse button using the "after_cancel" method, bu it continues to draw..</p>
  
  <p>Here is the code.</p>
  
  <pre><code>#! /usr/bin/env python
  from Tkinter import *
  import time
  import random
  
  
  tk = Tk()
  canvas = Canvas(tk, width=1920, height=1080, background="grey")
  canvas.pack()
  
  def xy(event):
      xm, ym = event.x, event.y
  
  def task():
      w=random.randint(1,1000)
      h=random.randint(1,1000)
      canvas.create_rectangle(w,h,w+150,h+150)
      def callback(event):
          if True:
              print("clicked2")    
              tk.after_cancel(task)
      canvas.bind("&lt;Button-1&gt;",callback)        
      tk.after(1000,task)           
  tk.after(1000,task)
  
  tk.mainloop()   
  </code></pre>