[Tkinter-discuss] How can mouse read canvas's object's info?

chenguang Zhang alix.zhang at gmail.com
Mon Apr 14 17:21:08 CEST 2008


Suppose there are several points on my canvas, each corresponds to a data of
the form [point index, point's x coordanate, point's y coordinate], all
these points are
created by the following sentence,

for point in self.data:
#self.data is a point list and has the form [point1, point2, ...]
     self.drawing.create_oval(point[1]-2, point[2]-2, point[1]+2,
                                 point[2]+2,fill='black',tags='Toselect')
#self.drawing is a Canvas
     self.drawing.tag_bind('Toselect', '<Any-Enter>', self.mouseEnter)

and the following is the self.mouseEnter function:

def mouseEnter(self,event):

self.CoordinateShow.configure(text='point:'+str(event.x)+','+str(event.y))
#self.CoordinateShow is a Label to show the point's information

I want to show the related information of the point when my mouse moves upon
them...
The KEY problem is: How can the mouse read out that point's OWN information,
such as the point's index, x and y coordinate, and even the point's color.
You see, the mouse's function here accually works on its own x and y
coordinates(event.x and event.y), not the point's value.
(now the self.mouseEnter function don't manipulate color, but my future work
will have to handle this...)

Thanks Very Much!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20080414/31968f88/attachment.htm 


More information about the Tkinter-discuss mailing list