2017-04-13 82 views
0
from tkinter import * 
    from PIL import ImageTk, Image 

    top = Tk() 

    file ='flame2.jpg' 
    filename = PhotoImage(file) 

    panel=PanedWindow() 
    panel = Label(top, image = filename) 

    panel.pack(side = "bottom", fill = "both", expand= "yes") 
    top.mainloop() 

回答

1

應使用PIL讀取這樣的複雜的圖像格式,並將它們作爲可理解對象Tkinter的:

from PIL import Image, ImageTk 
... 
my_image = Image.open("flame2.jpg") 
filename= ImageTk.PhotoImage(my_image) 
... 
panel = Label(top, image=filename) 
+0

my_image = Image.open( 「flame2.jpg」) AttributeError的:對象類型'圖像'沒有屬性'打開' 編譯你發送的代碼後,這是錯誤發生。 –

+0

嘗試'導入PIL.Image'而不是'從PIL導入圖像' –

+0

錯誤保持不變。 –