Nov-23-2021, 03:18 PM
Hi,
The (abbreviated) code below does exactly what it is supposed to do.
-Open an image
-resize it
-show it on canvas
But it shows no picture. I have found that this could be because of the garbage collector
that takes the picture away before it can be shown. Some say it is a tkinter "bug".
I can see it should work perfectly, if I add a last line that makes the program crash, e.g.
some operation with a non existant variable ! Now it shows the image!
I read that you must "hold on" to the picture by attaching it to something, like "label.image= img."
But I have no label, and neither "root", nor "canvas" have an .image property;
What to do ?
Paul
The (abbreviated) code below does exactly what it is supposed to do.
-Open an image
-resize it
-show it on canvas
But it shows no picture. I have found that this could be because of the garbage collector
that takes the picture away before it can be shown. Some say it is a tkinter "bug".
I can see it should work perfectly, if I add a last line that makes the program crash, e.g.
some operation with a non existant variable ! Now it shows the image!
I read that you must "hold on" to the picture by attaching it to something, like "label.image= img."
But I have no label, and neither "root", nor "canvas" have an .image property;
What to do ?
Paul
img = Image.open(foto) resized_img = img.resize((newW,newH),Image.LANCZOS) show_img =ImageTk.PhotoImage(resized_img) x_offset = int((1700-newW)/2) canvas.create_image(x_offset,0, image=show_img, anchor = NW)
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.