【问题标题】:error with tkinter mac os logo with .icns带有 .icns 的 tkinter mac os 徽标出现错误
【发布时间】:2021-03-27 13:27:11
【问题描述】:

我看不到 .icns 文件 蟒蛇,tkinter

代码:

windows = iconbitmap("any.icns")

enter image description here

【问题讨论】:

  • 请详细说明。添加我们可以用来提供帮助的详细信息(例如您的文件系统设置)。问一个可以回答的问题。包括您的完整代码。谢谢,欢迎来到 SO!

标签: python macos unix tkinter operating-system


【解决方案1】:

位图必须是ico类型,不能是png或jpg类型,否则图片不会显示为图标。 这些是解决方案

import tkinter as tk
root = tk.Tk()

root.tk.call('wm', 'iconphoto', root._w, tk.PhotoImage(file='/path/to/ico/icon.png')

root.mainloop()

import tkinter as tk
root = tk.Tk()

root.iconphoto(False, tk.PhotoImage(file='/path/to/ico/icon.png'))
root.mainloop()

【讨论】:

  • 但是我使用的是mac os,它与.ico不兼容,我应该使用.icns吗???
  • 您可以将 .incs 文件转换为 png 并尝试其中一种解决方案。
  • 请确保您提供了正确的图标位置。
  • 如果与 .py 文件位于同一位置,我只需指定图标的名称,例如在我的情况下为 py.icns?还是必须设置绝对路径?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-03
  • 1970-01-01
  • 2019-03-20
  • 2016-04-20
  • 2017-02-05
  • 1970-01-01
相关资源
最近更新 更多