我想在新窗口中显示图像,但出现错误。在
这是我的错误代码
photo = PhotoImage(file='img/dog')
File "C:\Users\Hyojae\Anaconda3\lib\tkinter\__init__.py", line 3542, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Hyojae\Anaconda3\lib\tkinter\__init__.py", line 3486, in __init__
raise RuntimeError('Too early to create image')
RuntimeError: Too early to create image
这是我的代码示例。在
谢谢你的帮助。在
^{pr2}$
您得到这样的区域是因为在图像加载到之前调用了
root.destroy
窗户。还有不能使用两个TK
实例,必须使用Toplevel检查链接以更好地理解。在除此之外,要在
toplevel
中显示图像,您需要为它创建引用,这样它就不会被垃圾回收Display image in Toplevel window 我就是这样做的。在我还使用
image subsample
来演示如何调整图像的大小sub = photo2.subsample(5, 5)
请检查这个link来阅读它相关问题 更多 >
编程相关推荐