首页 > 解决方案 > Pyautogui 不点击线程或子处理?

问题描述

我正在尝试打开 PDF 文件并使用 pywinauto 在 Adob​​e 中自动进行文件转换。为此,我想使用 pyautogui 单击菜单。

我这样定义函数:

def call_adobe(path):
    os.system('cmd /c ' + path)

def adobe_gui():
    btn_location = pyautogui.locateCenterOnScreen('Tools.png')
    if btn_location is None:
        print('Tools not found')
    else:
        pyautogui.moveTo(btn_location)
        pyautogui.click(btn_location, clicks=2)

我尝试了几种打开和单击 pdf 的选项:

x = threading.Thread(target=call_adobe, args=(path,))
y = threading.Thread(target=adobe_gui)
x.start()
y.start()
def adobe_gui(path):
    subprocess.Popen(path)  # <- HERE
    btn_location = pyautogui.locateCenterOnScreen('Tools.png')
    if btn_location is None:
        print('Tools not found')
    else:
        pyautogui.moveTo(btn_location)
        pyautogui.click(btn_location, clicks=2)

adobe_gui(path)
def adobe_gui(path):
    os.startfile(path)  # <- HERE
    btn_location = pyautogui.locateCenterOnScreen('Tools.png')
    if btn_location is None:
        print('Tools not found')
    else:
        pyautogui.moveTo(btn_location)
        pyautogui.click(btn_location, clicks=2)

adobe_gui(path)

在每种情况下,都会打开 pdf 并且 pyautogui 将光标移动到 Button 上方的正确位置。但它不会点击它!我也没有收到任何错误,它从不打印“找不到工具”。

有什么想法可行吗?

标签: pythonmultithreadingpyautogui

解决方案


推荐阅读