dreaminawake 发表于 2022-9-4 21:55:50

我哪里错了?

from PIL import Image
from 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'
这是为什么?

hrpzcf 发表于 2022-9-4 22:08:01

报错显示需要先创建窗口

ba21 发表于 2022-9-4 22:29:42

import tkinter as tk

tk = tk.Tk()

img = Image.open("1.png")
ImageTk.PhotoImage(image=img)

在tkinter 窗体循环内使用
页: [1]
查看完整版本: 我哪里错了?