Python Classes order of executing things
Question: I'm trying to make a window full of balloons disappear one-by-one (clicking on
it),using python2, but I'm a little confused where I could capture my mouse
events, in this moment, I'm not clicking anything, the code is attached. I'm
inspired by the code at: <http://effbot.org/zone/tkinter-canvas-find-
withtag.htm>, but I'm trying to do my own arrangements.

I'm going a little bit confused how Python Classes, attributes, and events are
related. Thanks for your ideas

    
    
    class Baloons:
       def __init__(self,wdw, dimension):
            self.canvas= Canvas(wdw, width=dimension, height=dimension)
            self.canvas.pack()
            self.update(self.canvas)
            self.click2(self.canvas)
    
       def click2(event, canvas):
           if  canvas.find_withtag(CURRENT):
                canvas.itemconfig(CURRENT, state="hidden")
                canvas.update_idletasks()
                canvas.after(200)
                canvas.delete("all")
                canvas.itemconfig(CURRENT, fill="red")
                self.update(canvas)
                self.click1(canvas)
    
       def update(self,canvas):
          for i in range(200):
              x, y = randint(0, 400-1), randint(0, 400-1)
              canvas.create_oval(x-5, y-5, x+5, y+5, fill="red")
    
       def click1(self,canvas):
            canvas.bind("<Button-1>", click2(canvas))
    
    if __name__ == "__main__":
         root=Tk()
         dimension = 200
         b=Baloons(root,dimension,delay)
         root.mainloop()
    


Answer: > I'm trying to make a window full of balloons disappear one-by-one (clicking
> on it)

That is not what your code is trying to do. Your code is hiding it, destroying
everything, trying to configure something you've destroyed, then recreating
new objects.

To answer the question of how to make balloons disappear by clicking on them
you can throw away about a fourth of your code.

Following is a working example. Mostly I just re-implemented `click2` to
remove all of the code unrelated to deleting the item under the cursor. I also
removed `click1` because I didn't see any reason to put the binding in a
function. You only need to set up the binding once.

I also removed the need to pass `canvas` around. Since you're using objects,
every method already has a way to access the canvas.

    
    
    from Tkinter import *
    from random import randint
    
    class Baloons:
       def __init__(self,wdw, dimension):
            self.canvas= Canvas(wdw, width=dimension, height=dimension)
            self.canvas.pack()
            self.update()
            self.canvas.bind("<Button-1>", self.click2)
    
       def click2(self, event):
           item = self.canvas.find_withtag(CURRENT)
           if item:
               self.canvas.delete(item)
    
       def update(self):
          for i in range(200):
              x, y = randint(0, 400-1), randint(0, 400-1)
              self.canvas.create_oval(x-5, y-5, x+5, y+5, fill="red")
    
    if __name__ == "__main__":
         root=Tk()
         dimension = 200
         b=Baloons(root,dimension)
         root.mainloop()
    

