在 Python 内将终端置于最前面

Bring terminal to the front in Python

有没有办法通过 python 脚本将 Linux 终端带到屏幕前面? Possibly 使用某种os。命令

I.e - 您的 python 脚本会打开一个填满屏幕的 GUI,但是如果发生某个事件,您希望在终端中打印出来以供查看,但不想/可以不要在 GUI 上显示此信息(所以请不要建议)

如果 possible,如果需要的话,再把它藏在另一个 windows 后面。

(Python 2, 顺便)

非常感谢任何建议。

没有任何普遍支持的方式。

一些终端应用程序可能支持以下控制序列。但是,这些序列没有标准化,大多数终端没有实现它们。

\e[5t  - move window to front
\e[6t  - move window to back

\e[2t  - minimize ("iconify") window
\e[1t  - un-minimize window

— 来自 http://rtfm.etla.org/xterm/ctlseq.html

"bring the Linux terminal to the front of your screen" 可能是在谈论 X Window 环境中的终端仿真器 运行。最终,这是通过向 window 经理提出请求来完成的。有不止一种方法可以做到这一点。

  • xterm(和其他一些终端仿真器)实现了 Sun control sequences for window manipulation (from the 1980s) which were reimplemented in dtterm during the early 1990s. xterm has done this since 1996 (patch #18).
  • Python: Xlib — How can I raise(bring to top) windows? mentions wmctl,一个命令行工具,允许您向 window 管理器发出各种请求。
  • xdotool 是另一个执行类似请求的命令行工具。
  • 最后,Can a WM raise or lower windows? 指出您可以编写自己的应用程序(并且因为 python 可以使用用 C 编写的共享库,您可以编写使用 X 库的脚本)。