2010/4/12 Filipe Pires Alvarenga Fernandes <ocefpaf@...>:
> Thanks for point TKinter to me. However, I'm stuck again.
>
> I've tried two approaches, one is following what you suggested:
>
> """ Tkinter """
> import Tkinter as tk
> root = tk.Tk()
> from PIL import Image, ImageTk
> image = ImageTk.PhotoImage(Image.open('map.png')) # load saved image
> #image = ImageTk.PhotoImage(im) # load image from StringIO
> tk.Label(root, image=image).pack()
>
> The other is to convert the PIL image to array and show with imshow()
>
> """ PIL to array """
> from matplotlib.image import pil_to_array
> rgba = pil_to_array(Image.open('map.png')) # load saved image
> #rgba = pil_to_array(im) # load image from StringIO
> rgba = rgba.astype(np.float32)/255.
> imshow(rgba)
>
> Both work fine for a saved image. However, they return strange errors
> when I tried to apply them to the image from "StringIO", or even for a
> saved image in the same script used to generate them. I guess that
> something I import from matplotlib is causing a conflict here.
>
> Here are the error messages:
>
> """ Tkinter """
> _tkinter.TclError: image "pyimage9" doesn't exist
>
>
> """ PIL to array """
> terminate called after throwing an instance of 'char const*'
Hi,
with the Tkinter PhotoImage, I think it's intended for use with
Tkinter.Canvas, and not compatible with Label. For what I know, it
works fine for me with Canvas (Windows). I guess what you end up with
is not a real PhotoImage but something faky.
Now, I cannot execute your script and dive in myself, because I
switched to another laptop, where I have to compile everything ... So
in some days, I will know more.
With the pil_to_image issue, I really have no idea. It's really quite
strange, isn't it? I mean, it should return a newly created
numpy.ndarray, and shouldn't borrow any memory with the PIL Image? I
really don't know at the moment, I'm sorry.
For the Tkinter issue, from your script it seems that you simply want
to display it, so give the Canvas a try. I used it in
http://github.com/friedrichromstedt/diagram_cl/blob/master/panels/tk/diagram.py
, start with update() and __init__().
hth for now,
Friedrich
|