Tkinter调用函数时显示图片

问题描述

我想在调用函数时在tkinter中显示图片.png(但也可以使用布尔showOnOff)。

这是我目前写的内容,但是图片没有出现。你有什么主意吗?

from tkinter import *
from tkinter import ttk
from PIL import Image,ImageTk 

root = Tk()

def display():
    # Use library PIL to display png picture
    path = '3d.png'
    img = ImageTk.PhotoImage(Image.open(path),Image.ANTIALIAS)
    panel = Label(root,image = img)
    panel.grid(row=1,column=0)

ButtonDisplay = ttk.Button(root,text="Display",command=display)
ButtonDisplay.grid(row=0,column=0)

root.mainloop()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)