Set Windows command-line terminal title in Python

Jonathan picture Jonathan · Sep 12, 2011 · Viewed 37.3k times · Source

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?

Answer

Jeffrey Harper picture Jeffrey Harper · Sep 27, 2012

This works for Python2.7 under Windows.

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