[Tkinter-discuss] tkinter.PhotoImage to PIL.Image

Michael Lange klappnase at web.de
Wed Dec 4 13:25:45 EST 2019


Hi,

sorry for the late replay.

On Sat, 30 Nov 2019 13:52:11 +0000
Vasilis Vlachoudis <Vasilis.Vlachoudis at cern.ch> wrote:

> Hi all,
>
> I have several images loaded as tkinter.PhotoImage, I want some to
> resize them The PhotoImage zoom accepts only integer values and the
> result is not that great. While if load them with PIL resize them and
> then convert to PIL.ImageTk it is much better. I found several
> references on how to convert from PIL to tkinter but I cannot find how
> to do the opposite so I can use the PIL resizing with the existing
> tkinter images.

Do you mean something like:

from PIL import Image, ImageTk
im = Image.open("image.png")
resized = im.resize((height, width), IMAGE.ANTIALIAS)
photo = ImageTk.PhotoImage(image=resized)

does not do the trick, you want to pass the tkinter.PhotoImage object to
PIL.Image.open() ? I don't think this is possible, at least without some
sort of trickery. What is it exactly that you want to achieve?

Regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

	"What happened to the crewman?"
	"The M-5 computer needed a new power source, the crewman merely
got in the way."
		-- Kirk and Dr. Richard Daystrom, "The Ultimate Computer",
		   stardate 4731.3.


More information about the Tkinter-discuss mailing list