[Image-SIG] Using ImageTk with Pmw.Blt

lightstone@acm.org lightstone@acm.org
Fri, 29 Nov 2002 17:07:22 -0800


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.

The piddle method also doesn't work for the same reason that an Image
object is used and Blt/Tcl *needs* a PhotoImage object.

What should I be doing here?   I want to get some of these graph
objects annotated and printed (on a Windows machine).


=============test program==============================
from Tkinter import *        # The Tk package
import Pmw                   # The Python MegaWidget package

import DebugWin
DebugWin.Take_all()     # trap stdout/stderr so I can see errors


import piddle,Image,ImageTk
from piddlePIL import *


master = Tk()                # build Tk-environment
g = Pmw.Blt.Graph(master)
g.pack(expand=1, fill='both')

g.line_create('Line',xdata=(0,10),ydata=(0,5),symbol='')               

################## snap ################################
def showSnap():
    img = ImageTk.PhotoImage()
    g.snap(img.__photo)
    img.__photo.write('file.gif')
##    img = PhotoImage(name="image", master=master)
##    g.snap(img)           # take snapshot
##    img.write("file.gif")  # and save it to file.
    print "Snapshot taken an written to file: file.gif"
    
    pc=PILCanvas(img)
    
# make row of buttons
buttons = Pmw.ButtonBox(master, labelpos='n', label_text='Options')
buttons.pack(fill='y', expand=1, padx=10, pady=10)


buttons.add('Snap',         command=showSnap)
buttons.add('Quit',         command=master.quit)

master.mainloop()


Howard Lightstone