tkinter不加图片路径,修改应用图表方法
作者:互联网
步骤1:
修改sTargetPicPath图片路径为自己图片的路径,先运行如下代码,得到图片的base64格式的图片码值
import base64
sTargetPicPath = r'C:\Users\user\Desktop\1.jpg'
with open(sTargetPicPath, 'rb') as open_icon:
b64str = base64.b64encode(open_icon.read())
print(b64b64str)
步骤2:
修改b63img的值为步骤1得到的值,运行如下代码例子,设置应用图标,大功告成。
import tkinter as tk
from base64 import b64decode
from PIL import Image, ImageTk
window = tk.Tk()
window.title("test")
window.geometry("420x200+0+0")
b64img = b'xxx'
icon_img = b64decode(b64img)
icon_img = ImageTk.PhotoImage(data=icon_img)
window.tk.call('wm','iconphoto',window,icon_img)
if __name__ == "__main__":
window.mainloop()
标签:__,tkinter,不加,img,base64,图表,window,import,icon 来源: https://blog.csdn.net/yangzhichao_csdn/article/details/122165515