9

I have been building a large python program for a while, and would like to know how I would go about setting the title of the program? On a mac the title of program, which has focus, is shown in the top left corner of the screen, next the apple menu. Currently this only shows the word "Python", but I would of course like to my program's title there instead.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
FrederikNS
  • 5,562
  • 2
  • 22
  • 36

2 Answers2

15

It depends on what type of application you have. If it's a graphical application, most graphical toolkits allow you to change the title of a window (tk, which comes with python, allows you to do this by calling the title() method of your window object, as does gtk, for which you can use the set_title() method on a Gtk.Window object)

If you're talking about changing the title of the terminal window (for mac or Linux), the you have this option (from here):

import sys
sys.stdout.write("\x1b]2;Another Title\x07")

For Windows, there's a different method:

import os
os.system("title Yet Another Title")
Daniel G
  • 67,224
  • 7
  • 42
  • 42
  • Thanks for the Windows answer as an aside. Was very useful to me. – Oddthinking Apr 11 '11 at 13:46
  • sys.stdout.write("\x1b]2;Another Title\x07") changes the current window title, what if i need to change the title of a terminal opened by python subprocess in linux – pankaj mishra Dec 07 '17 at 07:53
  • I'm looking for that answer as well. For me I'm calling terminal to open new windows and I want those new windows named. I'm trying to use cmd = echo -n -e "\033]0;xxx\007;python3 myFile.py – Keith Mar 13 '20 at 03:32
3

Since your program is interpreted by Python, then what actually is run is Python itself - the interpreter program. You would have to have your Python script merged with Python into a single executable and that would be able to have a separate name. For windows there is py2exe, that does that, but I have no idea if there is a similar tool for Mac OS (and if there is any need for that, there is some BSD under the hood right?).

gruszczy
  • 40,948
  • 31
  • 128
  • 181
  • Thanks a lot for the info, there is in fact an equivalent called "py2app", but I wasn't expecting that that was the only way to do it – FrederikNS Feb 24 '10 at 23:26