图像没有出现在 tkinter 的画布上

问题描述

我为我的模型制作了一个 GUI,用于在经过 CIFAR10 数据集训练后预测我的图像。我希望当我将图像添加到 GUI 时,它会出现在我的画布区域。但是,该图像未显示。但是当我点击我的“分类”按钮时,它仍然显示正确的结果。所以肯定是显示图像问题。我也在互联网上搜索并尝试了很多方法,但都没有很好的帮助。有人可以告诉我如何解决吗?非常感谢所有评论。提前致谢!

My GUI when predicting。如您所见,它仍然具有正确的输出,但图像没有显示(它应该显示在白色方块 - 画布的位置)

我的代码

# I just keep the overall structure of the code 
# as some parts are not related to this problem
import ...

def get_image():
    # Get path
    path = askopenfilename(filetype=(("jpg file","*.jpg"),("png file",'*.png'),("All files","*.*"),))

    # Load image
    img = Image.open(path)
    img = img.resize((350,350))
    img = ImageTk.PhotoImage(img)

    return path,img


class App(tk.Tk):
    def __init__(self): 

    # Code of 'browse' button
    def add_image(self):
        # Erase past record
        self.delete_image()

        # Load image
        path,img = get_image()

        # display path and image
        self.text.insert(END,path)
        self.canvas.create_image(0,anchor=NW,image=img)

    def classify_image(self):

    def delete_image(self):

app = App()
mainloop()

解决方法

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

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

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