13
votes

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?

2
Sigh. You'd think tkinter would just do this automatically when you set the title.Edward Falk
@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
Relevant XKCD: xkcd.com/979Edward Falk

2 Answers

13
votes

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>
-2
votes

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()