[英]How do you find the coordinates of the cursor in Python 3?
I found this code to be the most helpful to other people:我发现这段代码对其他人最有帮助:
x, y = win32api.GetCursorPos()
When I run this code, I get an error "NameError: name 'win32gui' is not defined on line ##".当我运行此代码时,我收到一个错误“NameError: name 'win32gui' is not defined on line ##”。
When trying to import the module:尝试导入模块时:
import win32gui
I get an error "ImportError: No module named win32gui on line ##".我收到错误“ImportError: No module named win32gui on line ##”。
I tried running:我尝试运行:
pip install win32gui
But it doesn't seem to work.但这似乎不起作用。 How can I use win32gui?如何使用win32gui?
You can use a third party module pyautogui, which is installed by: pip install pyautogui您可以使用第三方模块 pyautogui,通过以下方式安装: pip install pyautogui
Code for mouse position:鼠标位置代码:
import pyautogui
print pyautogui.position()
It will return a tuple with your x, y coordinate position它将返回一个带有您的 x、y 坐标位置的元组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.