我正在尝试使用 PIL 版本 6.2.1 在 python 3.7.3 中执行以下代码:
render = ImageTk.PhotoImage(Image.open(pic))
Run Code Online (Sandbox Code Playgroud)
但它会导致如下错误消息:
Traceback (most recent call last):
File "F:/python/test/test10.py", line 12, in <module>
render = ImageTk.PhotoImage(Image.open(pic))
File "C:\Users\erica\AppData\Roaming\Python\Python37\site-packages\PIL\ImageTk.py", line 118, in __init__
self.__photo = tkinter.PhotoImage(**kw)
File "C:\Users\erica\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 3545, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\erica\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 3489, in __init__
raise RuntimeError('Too early to create image')
RuntimeError: Too early to create image
Exception ignored in: <function PhotoImage.__del__ at 0x0000027A91FEB0D0>
Traceback (most recent call last):
File "C:\Users\erica\AppData\Roaming\Python\Python37\site-packages\PIL\ImageTk.py", line …Run Code Online (Sandbox Code Playgroud)