问题
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