小编MT_*_*276的帖子

AttributeError:模块“PIL.Image”没有属性“ANTIALIAS”

  • 我试图在我的 Tkinter GUI 中包含图像,因此我使用PIL
  • Image.ANTIALAIS不起作用。然而,Image.BILINEAR有效

这是一些示例代码:

import tkinter as tk
from PIL import Image, ImageTk

window = tk.Tk()

image = Image.open(r"VC.png")
image = image.resize((20, 20), Image.ANTIALIAS)

tk_image = ImageTk.PhotoImage(image)

image_label = tk.Label(window, image=tk_image)
image_label.pack()

window.mainloop()
Run Code Online (Sandbox Code Playgroud)

这是错误:

Traceback (most recent call last):
  File "<module1>", line 19, in <module>
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
Run Code Online (Sandbox Code Playgroud)
  • 我尝试重新安装 pip Pillow。它不起作用。
  • 我向ChatGPT询问了此事,它建议我升级到 Pillow 的最新版本。我使用的是最新版本(10.0.0)。

python python-imaging-library

63
推荐指数
3
解决办法
10万
查看次数

标签 统计

python ×1

python-imaging-library ×1