When you create an application with a GUI using Tkinter in Python, the name of your application appears as "Python" in the menu bar on OS X. How can you get it to appear as something else?
Asked
Active
Viewed 5,213 times
16
-
2Related http://stackoverflow.com/questions/8695926/remove-default-python-submenu-with-tkinter-menu-on-mac-osx – Andrei Jun 07 '15 at 10:53
-
*Sigh*. You'd think tkinter would just do this automatically when you set the title. – Edward Falk May 13 '21 at 01:22
-
@EdwardFalk - On a Mac, windows and apps are not generally synonymous the way they are on Windows and most Linux GUIs. So... no, I wouldn't expect that behavior. I'd expect some easy way of achieving the desired result, though. I'm curious why I posted this Q&A at 3:30 AM my timezone - what was I doing this night 6 years ago? It was just 3 weeks before my wedding. – ArtOfWarfare May 14 '21 at 03:57
-
Relevant XKCD: https://xkcd.com/979/ – Edward Falk May 14 '21 at 17:06
-
It might be a little late, but still would be interesting. Have you tried to alter the keyword arguments of `Tk` ? There are [several options](https://docs.python.org/3/library/tkinter.html#tkinter-modules) and I would guess that `baseName` is what you are looking for. – Thingamabobs Dec 01 '22 at 21:49
2 Answers
15
My answer is based on one buried in the middle of some forums. It was a bit difficult to find that solution, but I liked it because it allows you to distribute your application as a single cross platform script. There's no need to run it through py2app or anything similar, which would then leave you with an OS X specific package.
Anyways, I'm sharing my cleaned up version here to give it a bit more attention then it was getting there. You'll need to install pyobjc
via pip
to get the Foundation
module used in the code.
from sys import platform
# Check if we're on OS X, first.
if platform == 'darwin':
from Foundation import NSBundle
bundle = NSBundle.mainBundle()
if bundle:
info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
if info and info['CFBundleName'] == 'Python':
info['CFBundleName'] = <Your application name here>

ArtOfWarfare
- 20,617
- 19
- 137
- 193
-
8But this requires another third party library. Is there no way to do it within Tk? – Zizouz212 May 03 '15 at 03:48
-
1@Zizouz212: I have a script which automatically installs `pip` and uses it to install additional frameworks at runtime. It's a one time hick-up for the user when they run your application the first time (assuming they have an internet connection). So I consider third party libraries a very small cost. But if you'd like to go without it, I'd imagine you can look at the source for `NSBundle` and just take what you need from it and insert it directly into your own code. – ArtOfWarfare May 03 '15 at 03:53
-
2Tried to install `pyobjc` on the latest MBP15 - it took about half an hour. Not an option. – Andrei Jun 07 '15 at 10:31
-
2Well, that was mostly my fault. Apparently, PyObjC comes with OSX preinstalled. Previously I thought that I have installed it myself missing dedicated virtualenv and therefore uninstalled it. Installing it again takes A LOT of time, mostly due to utilizing just 1 core, see http://stackoverflow.com/questions/26228136/pip-build-option-to-use-multicore – Andrei Jun 07 '15 at 13:27
-
2@Andrei - All you actually need from `pyobjc` for this are the `Foundation`, `objc`, and `CoreFoundation` modules. I have verified that I am able to copy just those 3 folders from `site-packages` on one Python installation to another and that it works. If that's not light enough on requirements for you, then I believe those 3 modules are open source and you could probably cut and paste the relevant code from them into a single, slimmed down source file just for this single task. – ArtOfWarfare Jun 08 '15 at 21:26
-4
May not be quite what you need but I am surprised no one has mentioned the simple, platform independent way (works with Python 3.x on Win 7) :
from tkinter import Tk
root = Tk()
root.title( "Your title here" ) # or root.wm_title
and if you want to change the icon:
''' Replace the default "Tk" icon with an Application-specific icon '''
''' (that is located in the same folder as the python source code). '''
import sys
from tkinter import PhotoImage
program_directory = sys.path[ 0 ]
IconFile = os.path.join( program_directory ) + "\ApplicationIcon.gif"
IconImage = PhotoImage( file = IconFile )
root.tk.call( 'wm', 'iconphoto', root._w, IconImage )
root.mainloop()

user1459519
- 712
- 9
- 20
-
1I asked specifically about OS X (and want an answer that works on 2.7, although that probably doesn't make a difference.) Have you actually tried this on OS X and seen that it works? I have to assume I tried this before asking a year ago... I don't actually have a computer running OS X in front of me to test with right now. I'll look into this later when I have a chance to test on a Mac... – ArtOfWarfare May 10 '16 at 16:00
-
try this code on OSX with Pyton 2.x from Tkinter import * root = Tk() root.title( "Your title here" ) w = Label(root, text="Hello, world!") w.pack() root.mainloop() – user1459519 May 10 '16 at 18:16
-
Reposted due to stupid 5 minute limit on editing comments. For python 2.x use "from Tkinter" instead of "from tkinter" (for 3.x). Tkinter/tkinter is designed to be cross-platform compatable on at least Linux, Win and Mac. Try this code on OS X with Python 2.x - it's slightly modified from [link](http://effbot.org/tkinterbook/tkinter-hello-tkinter.htm): root = Tk() root.title( "Your title here" ) w = Label(root, text="Hello, world!") w.pack() root.mainloop() – user1459519 May 10 '16 at 18:28
-
3The question was regarding how to get rid of the "Python" program name in the top left of a Menu when running on MacOS. You answered a completely different question (setting the title in the middle of the app frame) on a different platform (Windows). – Marc Feb 24 '17 at 21:04
-
(Better late than never) Just a reminder that tkinter is platform independent. This solution should work on any reasonably modern version of python regardless of platform (though it might have to tweaked a bit for 2.x : e.g. change "from tkinter import Tk" to "from Tkinter import Tk") – user1459519 May 02 '18 at 23:42
-
1@user1459519 - sure, sure, it *should* work on macOS (Monterey, Python 3.8) but the fact is it doesn’t. – Simon Wright Apr 06 '22 at 10:07