Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change title of Tkinter application in OS X Menu Bar

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?

like image 402
ArtOfWarfare Avatar asked May 03 '15 03:05

ArtOfWarfare


1 Answers

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>
like image 80
ArtOfWarfare Avatar answered Oct 19 '22 02:10

ArtOfWarfare