pyautogui位置(Mac和Windows)
当我运行代码时,我会面临一些问题。 我正在Mac和Windows中开发相同的代码。
该函数从Pyautogui定位,即使我安装了OpenCV,也无法在Windows中工作。 Mac中的相同图像完美地
创建了一个功能,以了解该代码是否在Windows或Mac中运行,仅仅是因为分辨率
看到下面的代码
cond = True
while cond:
try:
x, y = auto.center(auto.locateOnScreen(settings.btnLogin, confidence=.5))
## Click in Windows
auto.click(x, y)
## Click in Mac
auto.click(x/2, y/2)
cond = False
except Exception as e:
print("Error", e)
return
,我只是无法理解它在Mac和Windows中工作的原因,而Windows则不断返回none none
有人可以帮助我吗?
Im facing some problems when i run my code.
Im developing the same code in Mac and in Windows.
The function LocateOnScreen from PyAutoGui is not working in Windows, even I installed OpenCV. The same image in MAC works perfetctly
I created a funtion to know if the code is running in Windows or Mac, just because the resolution
See the code below
cond = True
while cond:
try:
x, y = auto.center(auto.locateOnScreen(settings.btnLogin, confidence=.5))
## Click in Windows
auto.click(x, y)
## Click in Mac
auto.click(x/2, y/2)
cond = False
except Exception as e:
print("Error", e)
return
I just cant understand why it works in Mac and Windows keep returning None
Anybody can help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我想到了:
请确保您的图像大小与图像相同
您正在尝试使用机器人找到。
将其放在与“ .py”文件的同一文件夹中
“ btnlogin.jpg”。
工作代码应该是这样的:
这基本上是代码的核心,不是循环的,但是如果您只需要自动登录,则应该足够快:
让我知道是否某物不清楚或对您不起作用:)
So I came up with this:
Make sure your image is the same size as the one
you're trying to find with your bot.
Put it in the same folder as the ".py" file as
"btnLogin.jpg".
The working code should be like this:
This is basically the core of the code, doesn't cycle but should be fast enough if you just need to automate a login:
Let me know if something isn't clear or doesn't work for you :)
我设置了以预设尺寸打开的窗口,因此我拿了所有需要的印刷品。
我检查一下是否正在找到所有图像,然后发现它们正确。但是现在我将其运行在Mac上,以相同大小的窗口打开窗口,但是,它找不到图像。
我不知道为什么,但是即使有相同的窗口尺寸,Mac上的图像也会较小:(
我打开了一个大小(1440,900)的窗口,并拍摄了2张登录按钮的图片。其他
大小。
I set the window to open at a preset size, so I took all the prints I needed.
I checked to see if I was finding all the images, and I was finding them just right. But now I put it to run on Mac, to open the window with the same size, however, it doesn't find the images.
I don't know why, but even with the same window size, the image appears smaller on Mac :(
I open a window with the size (1440, 900) and took 2 pictures of the Login button. 1 picture in Mac and the other in Windows.
The size of the pictures: