Dưới đây là những gì tôi làm và nó hoạt động khá tốt ...
image = Image.open(Image_Location)
image = image.resize((250, 250), Image.ANTIALIAS) #The (250, 250) is (height, width)
self.pw.pic = ImageTk.PhotoImage(image)
Có bạn đi :)
EDIT:
Đây là của tôi báo cáo nhập:
from Tkinter import *
import tkFont
import Image #This is the PIL Image library
Và đây là đoạn code làm việc hoàn chỉnh tôi thích ví dụ này từ:
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
Và đây là các tài liệu lớp PhotoImage: http://www.pythonware.com/library/tkinter/introduction/photoimage.htm
Note ... Sau khi kiểm tra các tài liệu pythonware trên PhotoImage ImageTK của class (Rất thưa thớt) Tôi xuất hiện nếu đoạn mã của bạn hoạt động tốt hơn điều này cũng như khi bạn nhập Thư viện "Hình ảnh" PIL, thư viện PIL "ImageTK" và cả PIL và tkinter đều được cập nhật. Ở một khía cạnh khác, tôi thậm chí không thể tìm thấy cuộc sống mô-đun "ImageTK" cho cuộc sống của tôi. Bạn có thể đăng nhập của mình không?
tôi tiếp tục nhận được này "AttributeError: Ví dụ PhotoImage không có thuộc tính 'thay đổi kích thước ''. Tôi cần nhập gì? – rectangletangle
@ Anteater7171 Bao gồm một số thông tin khác – Joshkunz
Đó là (chiều rộng, chiều cao), không (chiều cao, chiều rộng). – Jacob