我用来pygetwindow通过它的标题将一个窗口带到前台。如果我从 cmd(和 PowerShell)运行 python 脚本,它会完美地工作。但是,如果我从任何其他终端(例如 Alacritty)运行它,提到的窗口不会进入前台,而是开始在任务栏中闪烁。
为什么会这样呢?我已将 Alacritty 配置为使用 cmd。
以下是我的代码的相关部分:
import pygetwindow
try:
window = pygetwindow.getWindowsWithTitle('foobar')[0]
window.activate()
except Exception as e:
#raise e
print("open foobar please")
exit(1)
Run Code Online (Sandbox Code Playgroud)
以下是我的 alacritty 配置的相关部分
# Shell
# You can set `shell.program` to the path of your favorite shell, e.g. `/bin/fish`.
# Entries in `shell.args` are passed unmodified as arguments to the shell.
# Default:
# - (macOS) /bin/bash --login
# - (Linux/BSD) user login shell
# - (Windows) powershell
shell:
program: …Run Code Online (Sandbox Code Playgroud)