简体   繁体   English

Python将图像插入Tkinter错误

[英]Python insert image into Tkinter error

I want to insert an image into my tkinter but I received error: 我想在tkinter插入图片,但是收到错误消息:

TclError: image "pyimage7" doesn't exist. TclError:图像“ pyimage7”不存在。

I am using WinPython-64-3.3.5.9. 我正在使用WinPython-64-3.3.5.9。 I tried "rozmery.gif" but didn't help. 我尝试了“ rozmery.gif”,但没有帮助。

    from tkinter import *        
    from PIL import ImageTk, Image

    app_root = Tk()

    #Setting it up
    img = ImageTk.PhotoImage(Image.open("rozmery.png"))

    #Displaying it
    imglabel = Label(app_root, image=img).grid(row=1, column=1) 

    app_root.mainloop()

You should keep a reference to the image before placing it: 在放置图像之前,应保留对其的引用:

imglabel = Label(app_root, image=img)
imglabel.image = img
imglabel.grid(row=1, column=1) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM