在 Python 中设置 Windows 命令行终端标题 [英] Set Windows command-line terminal title in Python

查看:68
本文介绍了在 Python 中设置 Windows 命令行终端标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Windows 机器上运行某个 Python 脚本的多个实例,每个实例都来自不同的目录并使用单独的 shell 窗口.不幸的是,Windows 为这些 shell 窗口中的每一个提供了相同的名称:

: C:\Windows\system32\cmd.exe - 

是否可以通过 Python 命令将此名称设置为其他名称?

解决方案

适用于 Windows 下的 Python2.7.

<预><代码>>>>导入 ctypes>>>ctypes.windll.kernel32.SetConsoleTitleA("我的新标题")

I'm running several instances of a certain Python script on a Windows machine, each from a different directory and using a separate shell windows. Unfortunately Windows gives each of these shell windows the same name:

<User>: C:\Windows\system32\cmd.exe - <script.py>

Is it possible to set this name to something else through a Python command?

解决方案

This works for Python2.7 under Windows.

>>> import ctypes
>>> ctypes.windll.kernel32.SetConsoleTitleA("My New Title")

这篇关于在 Python 中设置 Windows 命令行终端标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆