以下代码使Python在尝试创建PhotoImage实例时“意外退出”(它打印1并退出)。我在OSX10.9.5上,使用Python2.7.10,来自ActiveState的ActiveTcl 8.6.4,使用运行/运行模块从IDLE运行脚本。有什么线索吗?我完全不熟悉Python和所有的GUI模块
import numpy as np
import collections
import math
import Tkinter
from PIL import Image, ImageTk
# A root window for displaying objects
root = Tkinter.Tk()
# Convert the Image object into a TkPhoto object
im = Image.open('samples.png')
print 1
imgtk = ImageTk.PhotoImage(image=im)
print 2
# Put it in the display window
Tkinter.Label(root, image=imgtk).pack()
root.mainloop()发布于 2017-11-26 00:52:24
ImageTk.PhotoImage似乎已经崩溃了,至少在一些系统上是这样,包括OS X Sierra上的Python2.7。你可以使用Tkinter.PhotoImage代替,但是它只接受一个原始文件作为参数,这是很可怜的。
发布于 2015-08-10 08:57:33
你有没有尝试过链接这个:
import Tkinter
from PIL import Image, ImageTk
root = Tkinter.Tk()
imgtk = ImageTk.PhotoImage(file='test.jpg')
Tkinter.Label(root, image=imgtk).pack()
root.mainloop()https://stackoverflow.com/questions/31910080
复制相似问题