首页 > 解决方案 > Tkinter“pyimage5 不存在”

问题描述

我已经查看了几个类似的问题,但没有任何效果。我有一个 Tkinter 程序,按下按钮时会打开第二个窗口。第一个窗口中的所有图像都很好,但是当我打开第二个窗口时,当我要制作一个带有图像的按钮时,我会收到以下错误消息:

_tkinter.TclError: image "pyimage5" doesn't exist

图像的定义和存储方式如下:

add_icon = PhotoImage(file = 'data/add_icon.gif'), subtract_icon = PhotoImage(file = 'data/subtract_icon.gif')

他们是这样称呼的:

Button(edit, image = add_icon, command = add_new_pref, relief = FLAT) .grid(row = 2, column = 0, sticky = NSEW) Button(edit, image = subtract_icon, command = remove_pref, relief = FLAT) .grid(row = 3, column = 0, sticky = NSEW)

图像是在创建新窗口后定义的。有任何想法吗?

标签: pythontkinter

解决方案


推荐阅读