Reading coords from a scrolled Tkinter Canvas widget?

G. Willoughby never at mind.info
Sun Jun 2 11:44:17 EDT 2002


I am having a few problems reading the correct coords from a scrolled canvas
widget! e.g. i have a .jpg about 2000x2000pixels displayed inside a canvas
widget measuring 564x564pixels when i scroll the canvas using the attached
scrollbars i want to click the mouse and read the x/y coords of the .jpg
where my cursor is, not the canvas widget, any ideas? This is the code i
have at the minute:

[snip]
self.thumbnail=Canvas(self.frame1, bd=1, relief=SUNKEN, width=564,
height=564, scrollregion=(0, 0, 564, 564))
self.thumbnail.scrollX=Scrollbar(self.frame1, orient=HORIZONTAL)
self.thumbnail.scrollY=Scrollbar(self.frame1, orient=VERTICAL)
self.thumbnail['xscrollcommand']=self.thumbnail.scrollX.set
self.thumbnail['yscrollcommand']=self.thumbnail.scrollY.set
self.thumbnail.scrollX['command']=self.thumbnail.xview
self.thumbnail.scrollY['command']=self.thumbnail.yview
self.thumbnail.scrollX.pack(side=BOTTOM, fill=X)
self.thumbnail.scrollY.pack(side=RIGHT, fill=Y)
self.thumbnail.pack(side=LEFT)

self.thumbnail.bind("<Button-1>", self.getCoords)

def getCoords(self):
    xCoord=event.x
    yCoord=event.y
[/snip]

This code was working perfectly with images sized 564pixels but i've only
just noticed this will not work with bigger images  :(

--G. Willoughby





More information about the Python-list mailing list