python - 如何更改 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
解决方案
要更改 tkinter 应用程序中的窗口图标:
添加这段代码
root.iconbitmap("yourimage.ico")
推荐阅读
- powershell - 将字符添加到每行的 Out-File 内容?
- spring - 如何在没有 WebAppConfiguration 的集成测试中模拟 Spring 会话
- mule - DataWeave 1.0 - Mulesoft 查询
- javascript - 如何在Javascript循环中的每个项目后添加html换行符?
- python - 如何仅选择具有序列名称的列到列表中
- ruby-on-rails - 不应该工作但仍在工作的助手
- javascript - 如何从类别轴 Y 中隐藏标签
- android - osmdroid 无法解析方法“getInstance()”
- mysql - 百分比通配符不会返回完美匹配
- javascript - 我想在 Angular js 中的实时搜索结果中添加按键支持和按键支持。我的搜索结果即将上桌?