python-3.x - 设置窗口图标 tkinter macosx

标签 python-3.x macos tkinter icons

此行适用于我的 Windows 程序。

当我在 Mac OS X 上运行相同的文件时,我得到一个空白页而不是我的图标。

这是 window 线:

self.iconbitmap("Boss.ico")

我已经不懈地搜索了一个答案,我希望这个图标在两个平台上都可以使用。 self如果您想知道它是否是根,则是根 Tk 窗口。

注:我曾尝试通过加载照片图像和设置直通窗口属性来使用 icns、.xbm、.gif,所有这些都会在 mac 上产生相同的空白页面。

最佳答案

经过 5 天的搜索,这篇文章至少被浏览了 15 次,我直接转到了 tk/tcl 文档。如果我理解正确,显然没有办法在不使用特殊库或其他类型的黑客的情况下为 mac OS X 正确设置图标。如果 tkinter 库有特定于 mac 的文档,那就太好了,但可惜我没有找到。这是我找到的文档的一部分:

wm iconphoto window ?-default? image1 ?image2 ...? Sets the titlebar icon for window based on the named photo images. If -default is specified, this is applied to all future created toplevels as well. The data in the images is taken as a snapshot at the time of invocation. If the images are later changed, this is not reflected to the titlebar icons. Multiple images are accepted to allow different images sizes (e.g., 16x16 and 32x32) to be provided. The window manager may scale provided icons to an appropriate size. On Windows, the images are packed into a Windows icon structure. This will override an ico specified to wm iconbitmap, and vice versa.

On X, the images are arranged into the _NET_WM_ICON X property, which most modern window managers support. A wm iconbitmap may exist simultaneously. It is recommended to use not more than 2 icons, placing the larger icon first.

On Macintosh, this currently does nothing.



如果有人有可行的解决方案,请发布此信息。我想实现这一点,以便任何系统都可以打开新安装的 python 并运行我的应用程序,而无需安装任何其他库。

关于python-3.x - 设置窗口图标 tkinter macosx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48981184/

相关文章:

python - 将递归函数变成迭代函数

python - 在 python : Unknown characters 中读取 arduino 串行连接

objective-c - 使用 Xcode 的文本替换服务 - 不替换选定的文本

python - 如何通过单击按钮突出显示(选择)文本小部件中的文本?

适合屏幕的 Python Tkinter 应用程序

python - turtle 追踪器参数示例麻烦

python-3.x - 在 Networkx 中使用 k-core 时保留特定节点

macos - 如何构建 LLVM 并将其链接到 libc++?

swift - (OS X) 如何在用户切换 mac 桌面空间时得到通知

python - 为什么我的(增量)值呈指数级增长?