python的ImageTk.PhotoImage坑怎么解决(ImageTk.PhotoImage,python,开发技术)

时间:2024-04-28 01:04:22 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

    python%E7%9A%84ImageTk.PhotoImage%E5%9D%91%E6%80%8E%E4%B9%88%E8%A7%A3%E5%86%B3

接下来,请跟着小编一起来学习吧!

Exception in Tkinter callback
Traceback (most recent call last):
File "E:\Anaconda3_files\lib\site-packages\PIL\Image.py", line 2515, in fromarray
mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 3), '<f8')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "E:\Anaconda3_files\lib\tkinter__init.py", line 1705, in call__
return self.func(*args)
File "D:\Junior Spring\Digital Image Processing and Experiment\数字实验备份\结课实验\ImgProcessing.py", line 806, in Sobel_Sharpening
image = ImageTk.PhotoImage(Image.fromarray(img))
File "E:\Anaconda3_files\lib\site-packages\PIL\Image.py", line 2517, in fromarray
raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type

这里有个很关键的信息:Cannot handle this data type

1.如果没有安装PILLOW插件,请安装插件,使用 “pip install PILLOW”命令安装即可

2.生成PhotoImage对象:

fromPILimportImageTk

img=Image.open(filePath)

img=ImageTk.PhotoImage(img)

2.PhotoImage显示问题:显示空白框,大小是图片的真实大小

ifos.path.exists(filePath)andos.path.isfile(filePath):

iffilePathinimgDictandimgDict[filePath]:

returnimgDict[filePath]

img=Image.open(filePath)

img=ImageTk.PhotoImage(img)

imgDict[filePath]=img

returnimg

returnNone若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

本文:python的ImageTk.PhotoImage坑怎么解决的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Android Compose衰减动画Animatable怎么使用下一篇:

9 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18