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
#1
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?
Reply
#2
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.
Reply
#3
use:
x = root.winfo_pointerx() - root.winfo_rootx()
y = root.winfo_pointery() - root.winfo_rooty()
Reply
#4
Thank you! I think I was a little confused about widgets.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Take the variable of a cursor class delcencen 2 1,146 Feb-13-2023, 05:19 AM
Last Post: deanhystad
  [Tkinter] Modifications on cursor Zyxcel314 3 2,961 Jun-04-2018, 04:36 PM
Last Post: Larz60+
  [Tkinter] Problem of cursor force_tranquille 0 2,104 May-07-2018, 09:20 AM
Last Post: force_tranquille
  [Tkinter] Scroll at cursor position lollo 4 6,201 Jan-31-2018, 11:33 PM
Last Post: lollo

Forum Jump:

User Panel Messages

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