Tkinter -- does Canvas.find_closest work?

Russell E. Owen owen at
Fri Apr 21 19:00:28 EDT 2000

I am using Mac Python 1.5.2c1 (current) with Tkinter (based on Tk 8.0). 
I have a canvas called "cnv" with the following objects on it:
- 10 stars: tiny filled ovals tagged 'star'
- 9 grid markings: large unfilled ovals that are not tagged at all

I am trying to use the canvas method "find_closest" to find the closest 
star, ignoring the grid markings. Supposedly all I have to do is specify 
the start keyword with the value of a tag and it will find the closest 
object with that tag. Here's a code snippen and some of the output:

----- code snippet -----
nearestStar = self.cnv.find_closest (x=event.x, y=event.y, halo=0, 
print "found star ", nearestStar[0]
objList = self.cnv.find_withtag('star')
print "star list = ", objList

----- portion of resulting output ------
found star  23
star list =  (23, 24, 25, 26, 27, 28, 29, 30, 31, 32)
found star  20
star list =  (23, 24, 25, 26, 27, 28, 29, 30, 31, 32)

find_withtag is acting as if I never specified the tag at all. By moving 
the mouse pointer around I can get find_withtag to find objects 14 - 32. 
23-32 are clearly the stars. 14-22 are presumably the grid circles. The 
output above shows it finding one star and one grid circle.

I also tried supplying a numeric values (object IDs) to the "start" 
keyword. In this mode find_closest is supposed to find objects with IDs 
smaller than the value of "start". However, again it doesn't seem to 
have any effect. find_closest still will find any object on the canvas 
as I move the mouse pointer around.

Can anybody see an obvious mistake? Has anybody gotten the start keyword 
to work in Canvas method "find_closest"?

-- Russell

More information about the Python-list mailing list