I imported a file background_image.txt
containing the string reference background_image
a base 64 encoded graphic. When I compile the program I get the error in the error log:
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'
This is line #23
background_image = io.StringIO(base64.decode(background_image.background_image)) # line 23
This is the reduced verison of my program. This program creates a window using tkinter using the base 64 encoded graphic as the canvas background.
# 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()
According to the documentation, base64.decode takes 2 arguments: input and output.
You certainly want to use base64.b64decode(s)
which returns the decoded string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With