python - Tkinter Python 图像错误

标签 python tkinter tk-toolkit

我对为什么会收到此错误感到困惑。我查看了错误中指定的文件,并对 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.

最佳答案

“ImportError:DLL 加载失败:%1 不是有效的 Win32 应用程序。” 来自 Windows 本身,意味着您的 PIL 或 Tkinter 安装在您的 Windows 版本上不起作用。

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

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

关于python - Tkinter Python 图像错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17686053/

相关文章:

python - 将字典作为用户输入,然后保存到json文件中

python - 有没有一种方法可以更快地渲染点 OpenGL

Python - Tkinter - 图形用户界面

python - Tkinter askcolor 返回错误的 RGB 值?

从 R 中的 TclTk GUI 返回变量

tcl - 如何让我的 Tcl/Tk 希望应用程序将调试内容打印到控制台?

python - 使用 'pip install -r requirements.txt' 安装 python 包时出错

javascript - 找不到文件来编辑我下载的 Python 包的 css 内容

python - 为什么菜单没有显示在我的 Tkinter GUI 上?

tcl - 如何在 Tcl/Tk 中向 TreeView 添加复选框?