2013-07-16 171 views
2

我很困惑,为什么我得到这个错误,我查看了错误中指定的文件以及对PIL和实际错误进行了一些研究,任何帮助将不胜感激。此代码是一个示例代码,它不属于我,我下面的教程,我努力学习Python的一个新的GUI模块Tkinter Python图片错误

代码:。

from PIL import Image, ImageTk 
from Tkinter import Tk, Label, BOTH 
from ttk import Frame, Style 

class Example(Frame): 

    def __init__(self, parent): 
      Frame.__init__(self, parent) 

      self.parent = parent 

      self.initUI() 

    def initUI(self): 

      self.parent.title("Picture") 
      self.pack(fill=BOTH, expand=1) 

      Style().configure("TFrame", background="#333") 

      bard = Image.open("test.jpg") 
      bardejov = ImageTk.PhotoImage(bard) 
      label1 = Label(self, image=bardejov) 
      label1.image = bardejov 
      label1.place(x=20, y=20) 

def main(): 
    root = Tk() 
    root.geometry("300x280+300+300") 
    app = Example(root) 
    root.mainloop() 


if __name__ == '__main__': 
    enter code heremain() 

错误:

Traceback (most recent call last): 
    File "C:/Python27/pics.py", line 36, in <module> 
    main() 
    File "C:/Python27/pics.py", line 31, in main 
    app = Example(root) 
    File "C:/Python27/pics.py", line 12, in __init__ 
    self.initUI() 
    File "C:/Python27/pics.py", line 22, in initUI 
    bardejov = ImageTk.PhotoImage(bard) 
    File "C:\Python27\lib\site-packages\PIL\ImageTk.py", line 116, in __init__ 
    self.paste(image) 
    File "C:\Python27\lib\site-packages\PIL\ImageTk.py", line 181, in paste 
    import _imagingtk 
    ImportError: DLL load failed: %1 is not a valid Win32 application. 
+0

在'main()'中缩进缩进。 –

+0

这是什么意思 –

+0

我的意思是重新格式化你的粘贴代码。对于问题 - 检查Tkinter版本。 –

回答

1

"ImportError: DLL load failed: %1 is not a valid Win32 application."来自Windows本身,并且意味着您的PIL或Tkinter安装在您的Windows版本上不起作用。

一个潜在的原因是您正在使用Windows XP上使用VS 2012构建的版本;参见:

http://blogs.msdn.com/b/vcblog/archive/2012/06/15/10320645.aspx

+0

我重新安装了tkinter模块和python,并且似乎可以修复它 –