Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10593

Windows: setting title of console window

Date 2011-07-30 10:23 -0700
From Ethan Furman <ethan@stoneleaf.us>
Subject Windows: setting title of console window
Newsgroups comp.lang.python
Message-ID <mailman.1667.1312046688.1164.python-list@python.org> (permalink)

Show all headers | View raw


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~

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Windows: setting title of console window Ethan Furman <ethan@stoneleaf.us> - 2011-07-30 10:23 -0700

csiph-web