Windows: setting title of console window

E

Ethan Furman

I came across question http://stackoverflow.com/questions/6485678/ which
has to do with setting the console title from sitecustomize.py. With
some help from the folks on python-win32 (for the title portion ;) I
came up with this:

8<-- sitecustomize.py ---------------------------------
import sys
import time
from ctypes import windll

class SetTitle(object):
def __del__(self):
time.sleep(.1)
command = ' '.join(sys.argv)
windll.kernel32.SetConsoleTitleA(command)

sys.argv = SetTitle()
8<-----------------------------------------------------

I have a good number of python scripts being called to perform work, and
even the GUI modules have a console window -- no, it's not very
polished, but it's internal use only and it make the occasional bug
easier to track.

Having the python script's name in the console window (which otherwise
just says something like 'c:\windows\cmd.exe') is quite nice.

Oh, and if you're using Python 3, change SetConsoleTitleA to
SetConsoleTitleW.

~Ethan~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top