I would like to load an image in tkinter from a pygame surface and I am having a problem.
This is what I am currently trying:
image= pygame.image.tostring(surf, 'RGB')
tkimage= tkinter.PhotoImage(data= image)
canvas.create_image(0, 0, tkimage)
but I unfortunately get this error:
_tkinter.TclError: couldn't recognize image data
The
PhotoImageclass can only readGIFandPGM/PPMfiles, either directly from a file or asbase64encoded string.You should use the Python Imaging Library for loading and creating the image for Tk.
Here’s an example: