可以帮我看看我的这段代码里,为什么这张图片显示不出来,且会报这样的错--“_tkinter.TclError: image "pyimage3" doesn't exist”吗?
代码如下:
import tkinter as tk
import tkinter.ttk
from PIL import ImageTk
window_a_hp = tk.Tk()
window_a_hp.geometry('600x400+350+150')
window_a_hp.wm_title('None')
window_a_hp.resizable(False, False)
window_a_hp.topCanv = tk.Canvas(window_a_hp, bg='lightblue', width=600, height=100, bd=0)
window_a_hp.topCanv.pack(side=tk.TOP)
global m_photo
m_photo = ImageTk.PhotoImage(file="管理员头像.png")
window_a_hp.label1 = tk.Label(window_a_hp,image=m_photo, bd=0)
window_a_hp.label1.place(x=0, y=0)
图片如下:
报错如下:
这里可以看到tk.Canvas是生效了的,但是图片没加载出来,而且图片也是放在同一个文件夹里的,路径绝对没问题。