【问题标题】:How to change icon in tkinter [duplicate]如何更改tkinter中的图标[重复]
【发布时间】:2021-09-01 23:16:42
【问题描述】:
#MY Code
from tkinter import *

root = Tk()
root.geometry("1200x700")
root.title("MY_OS LOGIN/REGISTER")
icon=PhotoImage("C:\\Users\\Malay\\Desktop\\Main\\malay\\Python Scripts\\My OS GUI\\favicon.ico")
root.iconphoto(True,icon)

#我面临的错误 回溯(最近一次通话最后): 文件“C:\Users\Malay\Desktop\Main\malay\Python Scripts\My OS GUI\main.py”,第 35 行,在 root.iconphoto(真,图标) 文件“C:\Users\Malay\AppData\Local\Programs\Python\Python39\lib\tkinter_init_.py”,第 2125 行,在 wm_iconphoto self.tk.call('wm', 'iconphoto', self._w, "-default", *args) tkinter.TclError: failed to create color bitmap for "C:\Users\Malay\Desktop\Main\malay\Python Scripts\My OS GUI\favicon.ico"enter code here

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python tkinter


【解决方案1】:

在 tkinter 应用程序中更改窗口图标:

添加这段代码

root.iconbitmap("yourimage.ico")

【讨论】:

    【解决方案2】:

    这似乎有两个原因不起作用。 First Tkinter 不适用于 .ico 文件类型。其次,文件名是关键字参数,所以你的代码应该是这样的。

    #MY Code
    from tkinter import *
    
    root = Tk()
    root.geometry("1200x700")
    root.title("MY_OS LOGIN/REGISTER")
    # Comment out incorrect file type
    # icon=PhotoImage(file="C:\\Users\\Malay\\Desktop\\Main\\malay\\Python Scripts\\My OS GUI\\favicon.ico")
    # Using keyword file and using a png
    icon=PhotoImage(file="C:\\Users\\Malay\\Desktop\\Main\\malay\\Python Scripts\\My OS GUI\\favicon.png")
    root.iconphoto(True,icon)
    

    【讨论】:

      猜你喜欢
      • 2016-02-11
      • 2020-06-13
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多