pyautogui模块的Typewrite命令没有给出期望的输出

问题描述

我正在使用pyautogui模块并执行以下步骤:

  1. 导入的pyautogui
  2. 给予pyautogui.hotkey('winleft')

工作正常,窗口弹出。现在我要启动chrome。

  1. 发出命令pyautogui.typewrite('chrome\n')

它没有启动chrome,而是在“空闲”面板上输入chrome。

请帮助解决此问题,因为我想启动chrome。

OS:Windows 10
Python版本:3.8.1

解决方法

import webbrowser

url = 'about:blank'

# MacOS
#chrome_path = 'open -a /Applications/Google\ Chrome.app %s'

# Windows
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

# Linux
# chrome_path = '/usr/bin/google-chrome %s'

webbrowser.get(chrome_path).open(url)