Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
return self.func(*args)
File "C:\Users\saftarn\Desktop\pythonkod\mapexperiments
\mapgetobject.py", line 17, in callback
undermouse=find_closest(master.CURRENT)
NameError: global name 'find_closest' is not defined
from Tkinter import *
master = Tk()
w = Canvas(master, width=400, height=625)
w.pack(expand = YES, fill = BOTH)
mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\Maps\provinces-of-
sweden.gif')
w.create_image(30, 30, image = mapq, anchor = NW)
def key(event):
print "pressed", repr(event.char)
def callback(event):
clobj=event.widget
## undermouse=find_withtag(master.CURRENT)
undermouse=find_closest(master.CURRENT)
print repr(undermouse)
w.bind("<Key>", key)
w.bind("<Button-1>", callback)
w.pack()
mainloop()
from Tkinter import *
master = Tk()
mapq = PhotoImage(file = 'img.gif')
_id = w.create_image(0, 0, image = mapq, anchor = NW)
objects = {} # map id to object
objects[_id] = mapq
def key(event):
print "pressed", repr(event.char)
def callback(event):
x, y = w.canvasx(event.x), w.canvasy(event.y) # Translates a
window x,y coordinates to a canvas coordinate
_id = w.find_closest(x,y)[0] # Returns tuple containing the object
id
obj = objects[_id] # Finds object with given id
print 'color: %s' % obj.get(int(x), int(y))
ty very much. however i dont get the %s really. is % a symbol and then
replaced by obj.get-values?
anyway when clicked i get 3values, but there is intx and inty only.
where does the 3rd value come from and how do i refer to it?