how to replace the icon in a Tkinter app

别来无恙 提交于 2021-02-10 15:13:05

问题


I am using Python 3.5.0 on Windows 10 and want to replace this:


回答1:


To change the icon you should use iconbitmap or wn_iconbitmap I'm under the impression that the file you wish to change it to must be an ico file.

import tkinter as tk

root = tk.Tk()
root.iconbitmap("myIcon.ico")



回答2:


You must not have favicon.ico in the same directory as your code or namely on your folder. Put in the full Pathname. For examples:

from tkinter import *
root = Tk()

root.iconbitmap(r'c:\Python32\DLLs\py.ico')
root.mainloop()

This will work




回答3:


If you haven't an icon.ico file you can use PIL for changing your photo into .ico file

import tkinter as tk
from PIL import Image, ImageTk

root = tk.Tk()

ico = Image.open('test.png')
photo = ImageTk.PhotoImage(ico)
root.wm_iconphoto(False, photo)

root.mainloop()

See more




回答4:


input for tkinter

from tkinter import *

app = Tk()
app.title('Tk')
app.geometry('')

app.iconbitmap(r'C:\Users\User\PycharmProjects\HelloWorld\my.ico')
app.mainloop()

input for pyinstaller

pyinstaller --onefile -w -F -i "my.ico" my.py


来源:https://stackoverflow.com/questions/33137829/how-to-replace-the-icon-in-a-tkinter-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!