PILを使用してイメージをロードし、Tkinterによって作成されたウィンドウに表示する際に、非常に基本的なレベルで何かが欠けています。私は何をしようとしているの最も単純な形式は次のとおりです。TkinterでPILを使用するにはどうすればよいですか?
import Tkinter as TK
from PIL import Image, ImageTk
im = Image.open("C:\\tinycat.jpg")
tkIm = ImageTk.PhotoImage(im)
tkIm.pack()
TK.mainloop()
私は上記のコードを実行しようとすると、私は以下の取得:
RuntimeError: Too early to create image
Exception AttributeError: "PhotoImage instance has no attribute
'_PhotoImage__photo'" in <bound method PhotoImage.__del__ of
<PIL.ImageTk.PhotoImage instance at 0x00C00030>> ignored
私が確認したファイルが存在し、イメージエディタで開くことができ、im.show()を使用して表示することもできます。私は何が欠けていますか?
[Python Tkinter Error、 "Too Early to to Create Image"]の複製が可能です。(http://stackoverflow.com/questions/10236857/python-tkinter-error-too-early-to-create-image) –