[Image-SIG] Using ImageTk with Pmw.Blt

Fredrik Lundh fredrik@pythonware.com
Sun, 1 Dec 2002 17:55:40 +0100


"lightstone@acm.org" wrote:

> I am trying to use the .snap() method of Pmw.Blt to get a graph image
> which I can then convert using PIL to "something" (PDF or DIB or ??).
> 
> I can't seem to use the ImageTk.PhotoImage() method since apparently
> Pmw.Blt doesn't find the PhotoImage part of the object to pass to Blt.

PIL's PhotoImage object provides a one-way link between Tkinter
and PIL: you can create PhotoImage objects from PIL images, but
you cannot get the data back over to PIL.

since you're on Windows, you might be able to use the new Image-
Grab module to get a copy of the bitmap contents:

from Tkinter import *
from PIL import ImageGrab

def grabwidget(widget):
    x = widget.winfo_rootx()
    y = widget.winfo_rooty()
    w = widget.winfo_width()
    h = widget.winfo_height()
    return ImageGrab.grab((x, y, x+w, y+h))

root = Tk()

label = Label(root, text="Spam & Eggs")
label.pack()

label.update()

image = grabwidget(label)
image.save("c:\out.png")

</F>