小编4am*_*vim的帖子

Win 10:Cmd 可以将窗口带到前台,但任何其他终端都不能(即使提升)。为什么会这样呢?

我用来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)

cmd python-3.x setforegroundwindow windows-10 alacritty

3
推荐指数
1
解决办法
2761
查看次数