0
我想將base64
中的字符串解碼爲我的畫布背景的圖像。我知道我可以創建一個空的圖像文件,並使用此代碼寫它:無法將base 64 enocded圖形轉換爲畫布背景
fh = open("background.png", "wb")
fh.write(base64.b64decode(background_image.background_image))
fh.close()
但我要直接插入圖片到畫布背景wihout產生任何額外的文件,像這樣:
background_image = base64.b64decode(background_image.background_image)
background_image = ImageTk.PhotoImage(file=background_image)
canvas.create_image(0, 0, image=background_image, anchor=NW)
但我得到以下錯誤。
AtrributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'