gpt4 book ai didi

python - Tcl错误: couldn't recognize data in image file "background.png"

转载 作者:行者123 更新时间:2023-12-02 17:47:13 25 4
gpt4 key购买 nike

我最近已切换到 Python 2.7(从 3.4),并且在使用 Tkinter Photoimage 类读取 .png 文件时遇到问题。我说:

background = "background.png"
photo = tk.PhotoImage(file=background)

但我收到此错误:

Traceback (most recent call last):
File "main.py", line 36, in <module>
photo = tk.PhotoImage(file=background)
File "c:\Python27\lib\lib-tk\Tkinter.py", line 3323, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "c:\Python27\lib\lib-tk\Tkinter.py", line 3279, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "background.png"

最佳答案

img = ImageTk.PhotoImage(Image.open(background))

关于python - Tcl错误: couldn't recognize data in image file "background.png",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27180178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com