【问题标题】:Attribute Error while using Image Module from PIL library in Python 3在 Python 3 中使用 PIL 库中的图像模块时出现属性错误
【发布时间】:2020-03-11 16:20:56
【问题描述】:

我正在构建一个简单的 python 3 程序来打开和调整图像大小。我正在使用 Pycharm。我从 PIL 导入 Image 并尝试运行以下命令:

image1 = Image.open('<file location>')

但解释器显示图像类型没有打开属性的属性错误。

我的程序是:

from PIL import Image
from tkinter import *

root = Tk()

image2 = Image.open('hp png.png')

hp_image2 = Label(root , image = image2)

hp_image2.pack(fill = BOTH)

root.mainloop()

输出是: enter image description here

【问题讨论】:

  • 将输出包含为文本,而不是图像的链接
  • 请将输出添加为文本而不是图像。

标签: python python-3.x tkinter python-imaging-library attributeerror


【解决方案1】:

从 tkinter 的导入正在替换从 PIL 的导入。考虑更换

from tkinter import *

import tkinter as tk

并使用新的导入更新其余代码。

【讨论】:

    【解决方案2】:

    试试这个:

    import PIL.Image
    from tkinter import Tk
    
    image2 = PIL.Image.open('hp png.png')
    

    希望它会起作用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      • 2021-02-17
      • 2017-05-06
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      相关资源
      最近更新 更多