如何在tkinter中使用PIL图像

问题描述 投票:0回答:1

因此,我试图使用PIL打开图像,调整其大小,然后将其放在tkinter画布上。我已经尝试导入TkImage:

import TkImage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'TkImage'

from PIL import TkImage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'TkImage'

from PIL.Image import TkImage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'TkImage'

from PIL.Image import Image
i = Image.TkImage()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'Image' has no attribute 'TkImage'

所有这些都会引发例外。有人可以帮忙吗?

python tkinter python-imaging-library python-3.5
1个回答
0
投票

PIL中没有命名为TkImage的东西。但是,有一个名为ImageTk的东西。

from PIL import ImageTk
© www.soinside.com 2019 - 2024. All rights reserved.