I’m trying to place an image in a canvas using a function so I can update the image size and placement within the canvas.
I’m experiencing a really weird bug when I take the code and put it into a function, see Below:
If you comment out the canvas1.bind, the picture doesn’t show.
import tkinter as tk
from PIL import Image, ImageTk, ImageOps
window = tk.Tk()
canvas1 = tk.Canvas(window)
canvas1.pack()
def plant_image():
image = Image.open('test/IMG_5284.jpg')
image2 = ImageOps.fit(image = image, size = (156, 195))
pic = ImageTk.PhotoImage(image2)
canvas1.create_image(0,0, image = pic, anchor = 'nw')
# canvas1.bind('<MouseWheel>', lambda event: resizeimage(event, pic))
plant_image()
window.mainloop()
New contributor
Andrew McCrea is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.