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


Groups > comp.lang.python > #10593 > unrolled thread

Windows: setting title of console window

Started byEthan Furman <ethan@stoneleaf.us>
First post2011-07-30 10:23 -0700
Last post2011-07-30 10:23 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#10593 — Windows: setting title of console window

FromEthan Furman <ethan@stoneleaf.us>
Date2011-07-30 10:23 -0700
SubjectWindows: setting title of console window
Message-ID<mailman.1667.1312046688.1164.python-list@python.org>
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~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web