Welcome, guest | Sign In | My Account | Store | Cart

This DEMO is show how to write some text of your choice into the Title Bar of the Python terminal window.

Firstly it imports "time" just for this demo so that a simple time delay can be generated. Next the Python terminal window is written to for the 5 seconds of delay; see code. And finally the Title Bar is restored to normal...

A snapshot image can be seen here:-

http://wisecracker.host22.com/public/Title_Bar.jpg

Bazza...

Python, 26 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Title_Bar.py
# DEMO to show how to write some text into the Title Bar...
# Original code, (C)2013, B.Walker, G0LCU.
# Issued as Public Domain.
#
# Tested on OSX 10.7.5, Debian 6.0.x and PCLinuxOS 2009 using the default
# terminals running at least Python 2.5.2 to 3.3.2...
#
# A snapshot of the Title Bar here:-
#
# http://wisecracker.host22.com/public/Title_Bar.jpg
# To launch the DEMO enter:-
#
# >>> exec(open("/your/full/path/to/Title_Bar.py").read())<CR>
#
import time
#
print("Writing to the Title Bar...")
print("\x1B]0;THIS IS A TITLE BAR DEMO...\x07")
print("Wait for 5 seconds...")
time.sleep(5)
print("\x1B]0;\x07")
print("Title Bar returned to normal...")
#
# End of Title_Bar.py DEMO...
# Enjoy finding simple solutions to often very difficult problems...

I needed this little snippet to show the _current_ version of some code I was developing for python. It is Public Domain and you may do with it as you please...

Bazza...

11 comments

James Mills 10 years, 7 months ago  # | flag

Cool that's a neat trick :) Surely there's a more general purpose python library that understand most (if not all) terminal control codes?

Barry Walker (author) 10 years, 7 months ago  # | flag

Hi James...

I had thought about generating a _library_ to generate animation, colours, sound, buttons, radio-buttons, etc, etc... The problem is one can't guarantee that everything will work on all *NIX style platforms.

Even this may create a problem on someone's system, but for me, I used it as a function and filtered the version of any code I was working on and put it into the title bar so that I knew where I was...

I assume you were one of the guys who voted it up, thanks and to the other upvote too.

I do not code for a living, it is my hobby...

Barry Walker (author) 10 years, 7 months ago  # | flag

Someone else has voted it up again...

Many thanks from me...

Barry Walker (author) 10 years, 7 months ago  # | flag

In the last few minutes someone else has voted it up, many thanks to that person who has now put it at 5...

Bazza...

Barry Walker (author) 10 years, 7 months ago  # | flag

Voted up again, wow, many thnks to that person. You know who you are...

Barry Walker (author) 10 years, 6 months ago  # | flag

Voted up again, at 7 now...

Many thanks to whoever voted it up another notch...

Barry Walker (author) 10 years, 6 months ago  # | flag

Just got a reply from someone I know that this code works in multitab mode on:-

""" And to be more precise, multi tabs in LXTerminal. Python version " Python 2.7.5+ (default, Sep 19 2013, 13:48:49) [GCC 4.8.1] on linux2. Ubuntu LXDE 13.10 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram..... """

Thanks Ram for allowing me to repost here...

Bazza...

Barry Walker (author) 10 years, 6 months ago  # | flag

Just tested in a defualt CygWin terminal install and it works there too...

This I never expected, cool...

Bazza...

Barry Walker (author) 10 years, 4 months ago  # | flag

Just noticed another upvote today, 08-12-2013. Many thanks from me to this latest voter, you know who you are...

Wing K. Ng 10 years, 4 months ago  # | flag

Does it work on Windows?

Barry Walker (author) 10 years, 4 months ago  # | flag

Hi Wing...

No, not on the default CMD.EXE Windows Command Prompt. Windows has no concept of ANSI terminal escape codes so this is useful for UNIX, Linux, at least OSX 10.7.x and other POSIX compliant terminal emulators...

It DOES work on a default CygWin UNIX like terminal installation on Windows however! So in a round about sort of way it can be made to work on Windows. ;o)

Bazza...