python的ImageTk.PhotoImage坑怎么解决
导读:本文共1606.5字符,通常情况下阅读需要5分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要:接下来,请跟着小编一起来学习吧!python的ImageTk.PhotoImage大坑如果大家遇到这样的报错:Exception in Tkinter callbackTraceback (most recent call last): File "E:\Anaconda3_files\lib\site-packages\PIL\Image.py", line 2515, in... ...
目录
(为您整理了一些要点),点击可以直达。接下来,请跟着小编一起来学习吧!
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坑怎么解决的详细内容,希望对您有所帮助,信息来源于网络。