2

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.

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.
4
  • Tou ommited indent in main(). Commented Jul 16, 2013 at 20:13
  • I mean to reformat Your pasted code. To the problem - check Tkinter version. Commented Jul 16, 2013 at 20:16
  • why did some one add enter main code here im so confuesed Commented Jul 16, 2013 at 20:19
  • none of this make sense Commented Jul 16, 2013 at 20:25

1 Answer 1

1

"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.

One potential cause for this is that you're using a version built with VS 2012 on Windows XP; see:

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

Sign up to request clarification or add additional context in comments.

1 Comment

I reinstalled the tkinter moudle and python and that seemed to fix it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.