Question

so I upgraded to python 3.1.1 from 2.6 and i ran an old program of mine which uses tkinter.

I get the following error message which I don't recall getting in the 2.6 version.

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__
    return self.func(*args)
  File "C:\myprog.py", line 77, in <lambda>
    self.canvas.bind("<Button-3>", lambda event: myfunc_sub(event))
  File "C:\myprog.py", line 65, in myfunc_sub
    temp_ids = self.canvas.find_overlapping(self.canvas.coords(name)[0], self.canvas.coords(name)[1], self.canvas.coords(name)[2],self.canvas.coords(name)[3])
TypeError: 'map' object is not subscriptable

I'm pretty sure the line

temp_ids = self.canvas.find_overlapping(self.canvas.coords(name)[0], self.canvas.coords(name)[1], self.canvas.coords(name)[2],self.canvas.coords(name)[3])

was ok in the older version. I'm not sure what has changed so that the way i get each coordinate is not possible.

from the tkinter docs (pdf)

".find_enclosed ( x1, y1, x2, y2 ) Returns a list of the object IDs of all objects that occur completely within the rectangle whose top left corner is (x1, y1) and bottom right corner is (x2, y2).

.find_overlapping ( x1, y1, x2, y2 ) Like the previous method, but returns a list of the object IDs of all the objects that share at least one point with the given rectangle."

any ideas on how to fix this? please let me know if you need more info. the tkinter version i have is 8.5, i have idle 3.1.1 and python 3.1.1. i know the pdf link i provided is for 8.4, but i can't imagine there was a change in these functions.

thanks!

Was it helpful?

Solution

self.canvas.coords(name)

return a map object, and as the error states map object is unsubscriptable in python 3. you need to change coords to be a tuple or a list.

you need to change your code to be:

temp_ids = self.canvas.find_overlapping(*tuple(self.canvas.coords(name)))

OTHER TIPS

There were several breaking changes from Python 2.X to Python 3.X -- among them, map's functionality.

Have you run your script through 2to3 yet?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top