Python在PhotoImage中退出 [英] Python quits in PhotoImage
问题描述
以下代码使Python在尝试创建PhotoImage实例时意外退出"(打印1并退出).我在OS X 10.9.5上,使用的是Python 2.7.10,ActiveState的ActiveTcl 8.6.4,使用运行/运行模块从IDLE运行脚本.有什么线索吗?我对Python和所有GUI模块都是全新的
The following code makes Python "quit unexpectedly" when trying to create the PhotoImage instance (it prints 1 and quits). I'm on OS X 10.9.5, using Python 2.7.10, ActiveTcl 8.6.4 from ActiveState, running the script from IDLE using Run / Run Module. Any clue? I'm totally new to Python and all the GUI modules
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()
推荐答案
ImageTk.PhotoImage似乎已损坏,至少在某些系统上(包括OS X Sierra上的Python 2.7)已损坏.您可以改用Tkinter.PhotoImage,但它只将原始文件作为可怜的参数.
ImageTk.PhotoImage seems to be broken, at least on some systems including Python 2.7 on OS X Sierra. You can use Tkinter.PhotoImage instead, but it only takes a raw file as an argument which is pitiful.
这篇关于Python在PhotoImage中退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!