首页 > 解决方案 > 如何更改 tkinter 中的图标

问题描述

#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)

#Error 我正面临 Traceback(最近一次通话最后一次):文件“C:\Users\Malay\Desktop\Main\malay\Python Scripts\My OS GUI\main.py”,第 35 行,在 root.iconphoto(True ,icon) 文件 "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

标签: pythontkinter

解决方案


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

添加这段代码

root.iconbitmap("yourimage.ico")

推荐阅读