微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Pyautogui 不点击线程或子处理?

如何解决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()
  • 我将 adobe_gui 更改为包含 subprocess.Popen(path)(而不是对 call_adobe 函数进行多线程处理):
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)
  • 我将 adobe_gui 更改为包含 os.startfile(path)(而不是对 call_adobe 函数进行多线程处理):
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 会将光标移动到按钮上方的正确位置。但它没有点击它!我也没有收到任何错误,它从不打印“找不到工具”。

知道什么可行吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。