问题描述
限时送ChatGPT账号..如果我有:
from Tkinter import *
app = Tk()
...
app.mainloop()
我会使用 app.iconbitmap(...)
吗?
如果是这样,我将如何使用 this 作为文件,我应该导入 urllib
吗?
And if so, how would I go about using this as the file, and should I import urllib
?
推荐答案
您也可以使用它来替换 Tkinter
默认图标.
You can use this too replace the Tkinter
default icon.
import base64, PIL, urllib, Tkinter
from Tkinter import *
from PIL import ImageTk
from urllib import *
root = Tk()
raw_data = urllib.urlopen("http://dl.dropboxusercontent/s/qtlincxkbbiz1qv/stat.gif").read()
b64_data = base64.encodestring(raw_data)
image = PhotoImage(data=b64_data)
root.tk.call('wm', 'iconphoto', root._w, image)
root.mainloop()
然后将 .py
文件扩展名更改为 .pyw
以更改任务栏图标.
And then change the .py
file extension to .pyw
to change the taskbar icon.
.pyw
扩展告诉它使用 pythonw.exe
而不是 python.exe
运行,而是使用 pythonw 运行.exe
也让它在没有控制台的情况下运行.
The .pyw
extension tells it to run with pythonw.exe
instead of python.exe
, but running with pythonw.exe
also makes it run without the console.
因此,您要么在没有图标的情况下运行,要么在没有控制台的情况下运行.
So, you'll either have to run without the icon, or without the console.
这篇关于如何使用 URL 设置 tkinter 应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论