在 OS X 菜单栏中更改 Tkinter 应用程序的标题 [英] Change title of Tkinter application in OS X Menu Bar

查看:43
本文介绍了在 OS X 菜单栏中更改 Tkinter 应用程序的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用 Python 中的 Tkinter 创建具有 GUI 的应用程序时,您的应用程序名称在 OS X 的菜单栏中显示为Python".如何让它显示为其他内容?

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?

推荐答案

我的回答是基于一个埋在中间的一些论坛.找到该解决方案有点困难,但我喜欢它,因为它允许您将应用程序作为单个跨平台脚本分发.没有必要通过 py2app 或任何类似的东西来运行它,这会给你一个 OS X 特定的包.

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.

无论如何,我在这里分享我的清理版本是为了给它更多的关注,然后它到达那里.您需要通过 pip 安装 pyobjc 以获取代码中使用的 Foundation 模块.

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>

这篇关于在 OS X 菜单栏中更改 Tkinter 应用程序的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆