Python Forum

Full Version: Finding out what's under the cursor
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm new to Python, and way out of practice (15+ years out of practice) with any sort of programming. I don't have example code as I'm in the planning phase, and I'm not really sure how to ask what I'm looking for, so please bear with me.

I'm working on a project that will have a canvas. The user will be able to draw boxes and assign properties to the boxes.

I'd like to know if there's a way to detect whether a user's box exists at the mouse coordinates so that I can take one set of actions if there's no box there and get the user-defined properties of the box if there is one.

Most of this I can figure out. But how does one detect whether there's a box under the cursor if the box isn't a tkinter widget?
Why wouldn't it be a tkinter (or some other GUI tookit) widget? The base class for widgets is a thing that knows what to do when you click on it or type in it. Sounds like that is something you want. If you need a different appearance you can subclass an existing widget and override the paint method.
use:
x = root.winfo_pointerx() - root.winfo_rootx()
y = root.winfo_pointery() - root.winfo_rooty()
Thank you! I think I was a little confused about widgets.