【问题标题】:Tkinter Python Image errorTkinter Python图像错误
【发布时间】:2013-07-16 20:10:56
【问题描述】:

我对为什么会收到此错误感到困惑。我查看了错误中指定的文件,并对 PIL 和实际错误进行了一些研究。任何帮助将不胜感激。此代码是示例代码,它不属于我。我正在学习一个教程,我正在尝试为 python 学习一个新的 gui 模块。

代码:

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.

【问题讨论】:

  • 你在main()中省略了缩进。
  • 我的意思是重新格式化您粘贴的代码。对于问题 - 检查 Tkinter 版本。
  • 为什么有人在这里添加输入主代码我很困惑
  • 这些都没有意义

标签: python tkinter tk


【解决方案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

【讨论】:

  • 我重新安装了 tkinter moudle 和 python,这似乎解决了它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-29
  • 2021-05-31
  • 2015-10-02
  • 2017-02-14
  • 1970-01-01
  • 2015-11-23
  • 1970-01-01
相关资源
最近更新 更多