2017-04-13 85 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

错误保持不变。 –