Python Forum
[Tkinter] Finding out what's under the cursor
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Finding out what's under the cursor
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.
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.

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] cursor cross hairs want date not x index bapo10 0 531 Jun-27-2020, 08:14 PM
Last Post: bapo10
  [Tkinter] Modifications on cursor Zyxcel314 3 1,620 Jun-04-2018, 04:36 PM
Last Post: Larz60+
  [Tkinter] Problem of cursor force_tranquille 0 1,185 May-07-2018, 09:20 AM
Last Post: force_tranquille
  Screen Shots with mouse cursor anurag2904 3 4,844 Mar-06-2018, 05:36 AM
Last Post: Larz60+
  [Tkinter] Scroll at cursor position lollo 4 3,531 Jan-31-2018, 11:33 PM
Last Post: lollo

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020