Reputation: 10093
I'm creating a custom button using a canvas with a polygonal shape drawn to it. I've set the polygon to have a special activefill color and indeed it works, switching colors only when the mouse pointer is within the actual polygon's boundary (not just anywhere on the canvas).
That said, while I can bind to <Enter>
and <Leave>
, these apply to the entire canvas, not just within the polygon (where activefill color toggles). What do I bind to so I can trigger on the same state activefill does, leveraging the in-or-out calculation already done to that polygon by Tk itself?
Edit: As always, I did quite a bit of searching before submitting this question (and oddly, search on stackoverflow kept coming up completely empty today) and it was not clear that one needs to use tag_bind instead of bind to accomplish this in particular. Hopefully this Q&A will help others who search for "bind", "activefill" and "state" (and "create_polygon", and several other terms) in pursuit of this effect.
Upvotes: 0
Views: 527
Reputation: 386210
You would bind to the <Enter>
and leave event, but you should use the tag_bind method on the canvas rather than the bind
method. tag_bind
lets you set bindings on individual items on the canvas, or on groups of items that share the same tag.
Upvotes: 1