在Python 3中使用PIL库中的图像模块时出现属性错误

我正在构建一个简单的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

fc1138728 回答:在Python 3中使用PIL库中的图像模块时出现属性错误

从tkinter导入将替换从PIL导入。考虑更换

from tkinter import *

import tkinter as tk

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

,

尝试一下:

import PIL.Image
from tkinter import Tk

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

希望它能工作

本文链接:https://www.f2er.com/3095013.html

大家都在问