I'm trying to embed an image in a Tkinter canvas using PIL, and for some reason it's not displaying. Any Ideas?
There are no errors or warnings. Just a blank Tk window.
My code:
import Tkinter
from PIL import ImageTk, Image
class image_manip(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.ImbImage = Tkinter.Canvas(self)
self.ImbImage.pack()
i = ImageTk.PhotoImage(Image.open('test.png'))
self.ImbImage.create_image(0, 0, image=i)
def run():
image_manip(None).mainloop()
if __name__ == "__main__":
run()
My guess is that the image is getting garbage-collected. Try saving a reference to "i" (eg: self.image=i)
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