Jul-10-2023, 09:38 PM
Thanks for th info. As seeen from attached image, the map aare and several widtges (controls). All on root window, named window.
Map,https://github.com/TomSchimansky/TkinterMapView,
The map returns longitude/latitude coords when clicked, so I suppose I cant add a transparent window to hold the screen mouse movemennt event handler to avoid that controls (widtges) resets the coordinates.
I would like event report back coordinates untouced by controls.
I am thinking of adding values to reported x and y coordinates when mousepointer reach the map area, but that involves some nasty comparements :)
Ill look into your postof today tomorrow. thanks.
Map,https://github.com/TomSchimansky/TkinterMapView,
The map returns longitude/latitude coords when clicked, so I suppose I cant add a transparent window to hold the screen mouse movemennt event handler to avoid that controls (widtges) resets the coordinates.
I would like event report back coordinates untouced by controls.
I am thinking of adding values to reported x and y coordinates when mousepointer reach the map area, but that involves some nasty comparements :)
Ill look into your postof today tomorrow. thanks.
(Jul-10-2023, 06:03 PM)deanhystad Wrote: Are you sure this is something you want? I think I remember one of your earlier posts that included a map. Are your trying to find the mouse location in the map window? If so, the easiest way to do this is bind motion for the map only.
In this example I only bind potion events for the "position" label. Move the mouse inside the "position" label and it reports the mouse position relative to the label. Move the mouse outside the label and the motion() function is not called. I find this to be a most useful behavior since widgets generally don't care about mouse events that happen somewhere else.
The window does not need focus for the motion event to run. To verify I added an entry widget where you can type text. Press the Enter key and the text is copied to the position label. Now move the cursor over the position label and you will see the mouse position displayed. You can still type, so the entry has retained focus.
import tkinter as tk window = tk.Tk() def copy_entry(event): print(event) position["text"] = entry.get() def motion(event): position["text"] = f"{event.x}, {event.y}" entry = tk.Entry(window, width=10, font=("Ariel", 24, "bold")) entry.pack(padx=50, pady=20) entry.bind("<Return>", copy_entry) position = tk.Label( window, width=10, font=("Ariel", 60, "bold") ) # Save label object in variable. position.pack(padx=50, pady=50) position.bind("<Motion>", motion) window.mainloop()And if you really want to get the position of the mouse in the root window, you can ask for it.
import tkinter as tk window = tk.Tk() def copy_entry(event): print(event) position["text"] = entry.get() def motion(event): x, y = window.winfo_pointerxy() # Ignore the event info. Ask for the cursor position. position["text"] = f"{x}, {y}" entry = tk.Entry(window, width=10, font=("Ariel", 24, "bold")) entry.pack(padx=50, pady=20) entry.bind("<Return>", copy_entry) position = tk.Label( window, width=10, font=("Ariel", 60, "bold") ) # Save label object in variable. position.pack(padx=50, pady=50) window.bind("<Motion>", motion) window.mainloop()