gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:10:27 28 4
gpt4 key购买 nike

如何从 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com