python - Pyautogui 不点击线程或子处理?
问题描述
我正在尝试打开 PDF 文件并使用 pywinauto 在 Adobe 中自动进行文件转换。为此,我想使用 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)
- 我将 pyautogui.FAILSAVE 更改为 False
在每种情况下,都会打开 pdf 并且 pyautogui 将光标移动到 Button 上方的正确位置。但它不会点击它!我也没有收到任何错误,它从不打印“找不到工具”。
有什么想法可行吗?
解决方案
推荐阅读
- android - kotlin 类,我在类外修改了一个列表,它最终修改了类内的值
- python - 使用 ffmpeg 与 Audacity 从 mp3 创建的 wav 文件的巨大差异
- python - VS Code - 智能感知变化
- unity3d - Unity - 对象很快撞到另一个对象
- sql - 如何在字符串中分隔 SQL 变量
- git - 在 macOS 上使用树过滤器和 sed 从 Git 提交中删除敏感数据
- python - 使用 sympy 求解方程
- c# - 具有延迟的 TPL 数据流队列
- python - 列出谷歌云计算引擎活动实例
- c++ - 如何在 OpenFrameworks 中加载文件