我正在尝试编写一个脚本,它可以自动化工作中无聊的东西。为此,我使用“pyautogui”并完成了大部分脚本。操作系统是Windows btw。
我的问题是,我目前正在使用time.sleep()命令让脚本在进程的每个步骤之间工作,但最好检测某个像素的RGB值。
我现在所做的就是这样;
pyautogui.click(req_management_find[0],req_management_find[1])
time.sleep(2)
pyautogui.click(req_management_print[0],req_management_print[1])
while True:
time.sleep(0.5)
pix=pyautogui.pixel(1348,131)
if pix[1] == 27 and pix[2] == 161 and pix[3] == 226:
break
else:
time.sleep(0.5)
pyautogui.click(req_print_close[0],req_print_close[1])
这只是永远等待而不是打破while循环。我已经使用pyautogui.displayMousePosition()
读取了像素的RGB值。通常为(255,255,255)。在一段不确定的时间之后,我正在尝试编写脚本的程序会弹出一个弹出窗口,将像素的RGB从(255,255,255)更改为(27,161,226)。
为什么我的代码没有检测到这种变化?
指数从0开始,所以它是:
if pix[0] == 27 and pix[1] == 161 and pix[2] == 226:
或者您可以通过使用以下内容使其更明确:
if pix.red == 27 and pix.green == 161 and pix.blue == 226:
当然,正如@Aditya Santoso所建议的那样:
if pix == (27, 161, 226):