Insert a .jpg in a canvas with tkinter and Python 3.2 -
so want put .jpg in canvas, found on internet use pil i'm using python 3.2 pil doesn't work. can insert .jpg in canvas python 3.2 ?
just save else viewing hunting around bits , pieces (like did)
as martijn pieters said use pillow rather pil, code looks same
from tkinter import tk, canvas pil import imagetk, image root = tk() #create canvas canvas = canvas(root, width=400, height=300) canvas.pack() # load image file im = image.open('test_image.jpg') # put image canvas compatible class, , stick in # arbitrary variable garbage collector doesn't destroy canvas.image = imagetk.photoimage(im) # add image canvas, , set anchor top left / north west corner canvas.create_image(0, 0, image=canvas.image, anchor='nw') root.mainloop()
Comments
Post a Comment