2014-11-23 51 views
0

我導入了一個文件background_image.txt,其中包含字符串參考background_image是一個base 64編碼圖形。當我編譯程序,我得到的錯誤日誌中的錯誤:解碼base 64編碼圖形時無法理解錯誤

Traceback (most recent call last): 
    File "main.py", line 23, in <module> 
    background_image = io.StringIO(base64.decode(background_image.background_image)) 
TypeError: decode() missing 1 required positional argument: 'output' 

這是線#23

background_image = io.StringIO(base64.decode(background_image.background_image)) # line 23 

這是減少verison我的計劃。這個程序使用tkinter創建一個窗口,使用base 64編碼圖形作爲畫布背景。

# modules 
from tkinter import * 
from PIL import ImageTk, Image 
import io 
import base64 

# imported files 
import background_image 

# variables 
background_image = io.StringIO(base64.decode(background_image.background_image)) # line 23 

# window creation 
root = Tk() 

# canvas creation 
canvas = Canvas(root, width=600, height=600, bd=-2) 
canvas.pack() 

# canvas attributes 
background = ImageTk.PhotoImage(file=background_image) 
canvas.create_image(0, 0, image=background, anchor=NW) 
text = canvas.create_text(125, 75, anchor=CENTER) 

# end 
root.after(0, display) 
root.mainloop() 

回答

3

根據the documentation,base64.decode有2個參數:輸入和輸出。

您當然想要使用base64.b64decode(s),它返回解碼後的字符串。

+0

這兩個參數都應該是文件。 – 2014-11-23 12:58:51

相關問題