tkinter将无法识别base64编码的字符串中的图像数据

时间:2014-11-27 16:22:28

标签: python python-2.7 tkinter

我从Python 3.4更改为Python 2.7,在调试我的脚本时,我发现解释器无法读取字符串中编码的base64图形。我想使用编码图像作为tkinter画布的背景,但我现在无法像在Python 3.4中那样这样做:

background="""
iVBORw0KGgoAAA #....continues
"""

photo = tk.PhotoImage(data=background)
width, height = photo.width(), photo.height()
canvas = tk.Canvas(root, width=width, height=height, bd=-2)
canvas.pack()
canvas.create_image(0, 0, image=photo, anchor="nw")

当我运行脚本时,我收到此错误:

>Traceback (most recent call last):
  File "main.py", line 31, in <module>
    photo = tk.PhotoImage(data=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 image data

0 个答案:

没有答案
相关问题