Added Window.mouse_location

This commit is contained in:
PySimpleGUI 2021-10-31 14:52:33 -04:00
parent d3012ea16b
commit c003209bb8
1 changed files with 16 additions and 1 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "4.53.0.10 Unreleased" version = __version__ = "4.53.0.11 Unreleased"
_change_log = """ _change_log = """
Changelog since 4.53.0 released to PyPI on 24-Oct-2021 Changelog since 4.53.0 released to PyPI on 24-Oct-2021
@ -41,6 +41,8 @@ _change_log = """
4.53.0.10 4.53.0.10
Made right click menus propagate down container elements. Previously only the Window's right click menu was used. Made right click menus propagate down container elements. Previously only the Window's right click menu was used.
Now setting a right click menu on a Column, Frame, Tab will add the menu to elements inside the container element. Now setting a right click menu on a Column, Frame, Tab will add the menu to elements inside the container element.
4.53.0.11
Added new Window method - Window.mouse_location(). Returns the (x,y) location of the mouse pointer
""" """
__version__ = version.split()[0] # For PEP 396 and PEP 345 __version__ = version.split()[0] # For PEP 396 and PEP 345
@ -10262,6 +10264,19 @@ class Window:
except: except:
print('Transparent color not supported on this platform (windows only)') print('Transparent color not supported on this platform (windows only)')
def mouse_location(self):
"""
Return the (x,y) location of the mouse relative to the entire screen. It's the same location that
you would use to create a window, popup, etc.
:return: The location of the mouse pointer
:rtype: (int, int)
"""
if not self._is_window_created('tried Window.mouse_location'):
return (0,0)
return (self.TKroot.winfo_pointerx(), self.TKroot.winfo_pointery())
def grab_any_where_on(self): def grab_any_where_on(self):
""" """
Turns on Grab Anywhere functionality AFTER a window has been created. Don't try on a window that's not yet Turns on Grab Anywhere functionality AFTER a window has been created. Don't try on a window that's not yet