tkinter and events

Doug Hellmann doughellmann at mindspring.com
Fri Jun 11 10:11:41 EDT 1999


Paul Stillwell wrote:
> 
> So, when I run the code and double click on o1, I get:
> 
> >>> Clicked on domain 20
> 
> which is the last object I created even though I double clicked on the first
> object.  What am I doing wrong?

The reason you're always seeing the same value is that the call in
MyTestObject.__init__ to bind <Double-1> on the canvas always changes
the existing binding on the *canvas*, but what you want is to bind
events on the *rectangle*.

Try changing these two lines:

self.Box = Rectangle(Parent, self.Begx, self.Begy, self.Endx,
                             self.Endy)
...
self.Canvas.bind('<Double-1>', self.DoubleClickHandler)

to:

self.Box = Rectangle(Parent, self.Begx, self.Begy, self.Endx,
                             self.Endy,
                             fill='white')
...
self.Box.bind('<Double-1>', self.DoubleClickHandler)

I added the fill to the Rectangle so that I could double click on it
more easily.  Then, the important change is to use the bind method of
the Rectangle object, instead of the Canvas.

Doug




More information about the Python-list mailing list