简体   繁体   English

Tkinter Python图像错误

[英]Tkinter Python Image error

I"m confused as to why I'm getting this error. I have looked into the file specified in the error as well as done some research on PIL and the actual error. Any help would be appreciated. This code is an example code, it doesn't belong to me. I'm following a tutorial I'm trying to learn a new gui module for python. 我对为什么会收到此错误感到困惑。我已经研究了错误中指定的文件,并对PIL和实际错误进行了一些研究。我们将不胜感激。此代码是示例代码,它不属于我,我正在学习一个教程,试图为python学习一个新的gui模块。

Code: 码:

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()  

Error: 错误:

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.

"ImportError: DLL load failed: %1 is not a valid Win32 application." is from Windows itself, and means that your PIL or Tkinter install doesn't work on your Windows version. 来自Windows本身,这意味着您的PIL或Tkinter安装不适用于Windows版本。

One potential cause for this is that you're using a version built with VS 2012 on Windows XP; 造成这种情况的一个潜在原因是您在Windows XP上使用的是VS 2012内置的版本。 see: 看到:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM