這裏是我做的,它工作得很好......
image = Image.open(Image_Location)
image = image.resize((250, 250), Image.ANTIALIAS) #The (250, 250) is (height, width)
self.pw.pic = ImageTk.PhotoImage(image)
你去那裏:)
編輯:
這裏是我的進口說明:
from Tkinter import *
import tkFont
import Image #This is the PIL Image library
這裏是完整的工作代碼,我適應從這個例子:
im_temp = Image.open(Path-To-Photo)
im_temp = im_temp.resize((250, 250), Image.ANTIALIAS)
im_temp.save("ArtWrk.ppm", "ppm") ## The only reason I included this was to convert
#The image into a format that Tkinter woulden't complain about
self.photo = PhotoImage(file="artwrk.ppm")##Open the image as a tkinter.PhotoImage class()
self.Artwork.destroy() #erase the last drawn picture (in the program the picture I used was changing)
self.Artwork = Label(self.frame, image=self.photo) #Sets the image too the label
self.Artwork.photo = self.photo ##Make the image actually display (If I dont include this it won't display an image)
self.Artwork.pack() ##repack the image
這裏是光象類文檔:http://www.pythonware.com/library/tkinter/introduction/photoimage.htm
注... 檢查上ImageTK的光象的pythonware文檔後類(這是非常稀疏的)我看來,如果你的代碼片段工作得比這更好,只要你導入PIL「Image」庫和PIL「ImageTK」庫並且PIL和tkinter都是最新的。另一方面,我甚至無法在我的生活中找到「ImageTK」模塊的使用壽命。你可以發佈你的進口?
我不斷收到這個「AttributeError的:光象實例沒有屬性「調整「」。我需要導入什麼? – rectangletangle 2010-11-01 02:26:34
@ Anteater7171包含更多信息 – Joshkunz 2010-11-01 23:40:10
它是(寬度,高度),而不是(高度,寬度)。 – Jacob 2018-02-27 20:08:35