Setting the Title of the script window

Alex Martelli aleax at aleax.it
Wed Apr 23 06:57:10 EDT 2003


Xnedra wrote:

> Hi there,
> 
> is there a possibility to set the title of the window the python
> script was started in?
> I know it is possible with dos with these lines:
> 
> if os.name == "nt":
>   cmdline = 'TITLE TestTitle'
>   os.system(cmdline)
> 
> but i would like to set it independent of the operating system. Is
> there a python command for this or does anyone know the corresponding
> commandline for unix?

Unfortunately (in this context), "unix" does not have a single way
to implement "text windows" -- there are many such beasts!

Fortunately, most such beasts emulate to some extent the oldest of
them all, 'xterm'.  To set the window title under xterm, you must
print to the terminal a string with some escape sequences --

def set_xterm_title(title):
    print '\033]0;%s\007' % title

This will also work on a KDE "Konsole" and no doubt several other
terminal emulators -- but, I think, not ALL of them.


Alex





More information about the Python-list mailing list