我哪里错了?
from PIL import Imagefrom PIL import ImageTk
import tkinter as tk
img = Image.open("./ico.jpg")
ImageTk.PhotoImage(image=img)
就是想创造一个ImageTk的对象
抛出了这个错误
RuntimeError: Too early to create image
Exception ignored in: <function PhotoImage.__del__ at 0xffffbd30e670>
Traceback (most recent call last):
File "/home/uos/miniconda3/lib/python3.9/site-packages/PIL/ImageTk.py", line 118, in __del__
name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
这是为什么? 报错显示需要先创建窗口 import tkinter as tk
tk = tk.Tk()
img = Image.open("1.png")
ImageTk.PhotoImage(image=img)
在tkinter 窗体循环内使用
页:
[1]