python - 在 Python 中设置 GNOME 终端窗口标题?

标签 python terminal

如何从 Python 设置 GNOME 终端的窗口标题?

我正在从不同的终端运行多个 python 脚本。我希望 python 脚本在执行后自动将窗口标题设置为我可以在脚本中修改的某些状态文本。

最佳答案

您可以使用XTerm control sequence :

print(b'\33]0;title you want\a')

注意:以上语句将打印额外的换行符。为了避免这种情况,请使用sys.stdout.write:

import sys
sys.stdout.write(b'\33]0;title you want\a')
sys.stdout.flush()

在 Python 3.x 中:

print('\33]0;title you want\a', end='')
sys.stdout.flush()

在 Python 3.3+ 中:

print('\33]0;title you want\a', end='', flush=True)

或者

sys.stdout.buffer.write(b'\33]0;title you want\a')
sys.stdout.buffer.flush()

关于python - 在 Python 中设置 GNOME 终端窗口标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25872409/

相关文章:

python - 在 Python 中使用 Multiprocessing+Threads 加速应用程序时遇到问题

linux - Arch Linux 的 Gnome 终端不工作

python - “用户”对象不可迭代

python - 在 python 列表理解中打印(或执行语句)

python - 使用 pandas 从数据框中的列中仅删除前两个字符

python - Pybrain的网络架构的数据结构是怎样的?

mysql - 如何从终端从远程服务器下载 mySQL 表

shell - unix 管道命令的调试器

linux - 如何在Linux终端中动态显示结果?像 'top' 命令

linux - 捕获到/dev/tty 的直接重定向