我想检查一下桌面应用程序按钮是否可点击。是否有任何方法可以通过使用pyautogui来检查这一点?
我有一个按钮名称Login,如果我们同时提供用户名密码和文本字段。
这将需要启用和禁用按钮的图像:The images the program wants must be the same resolution.
import pyautogui
import keyboard #pip install keyboard
while True: # I added this loop to make sure that the image will be found.
# Sometimes the image is on the screen but pyautogui cant find it at once so i will make it check it repeatedly for the image.
res_d = pyautogui.locateCenterOnScreen('disabled.png') # capture the image by taking screenshot and cropping it
if res_d == None:
print("Enabled")
res_e = pyautogui.locateCenterOnScreen('enabled.png') # capture the image by taking screenshot and cropping it
if res_e == None:
print("Disabled")
if keyboard.is_pressed('q'): # Change this to the logic you want to use for breaking the loop.
break