saving a tkinter canvas to gif

B

biner

Hello,

Is there any way to save a canvas created with tkinter to a gif (or
any other graphic) without using PIL (I cannot build it on our unix
machine)? For example with this simple code :from Tkinter import *

root=Tk()
base=Canvas(root,width=50,height=50)
base.create_rectangle(0,0,50,25,fill='red')
base.create_rectangle(0,25,50,50,fill='blue')

base.pack()
root.mainloop()
<<<
How can I save the image with the two colored rectangle onto a graphic
file?
I looked on google and in the documentation but I didn't find how to
do it. Thanks for any help.

Sebastien.
(e-mail address removed)
 
?

=?ISO-8859-1?Q?Mickel_Gr=F6nroos?=

Is there any way to save a canvas created with tkinter to a gif (or
any other graphic) without using PIL (I cannot build it on our unix
machine)?

Have you tried the postscript method of Tkinter.Canvas?
base=Canvas(root,width=50,height=50)
base.create_rectangle(0,0,50,25,fill='red')
base.create_rectangle(0,25,50,50,fill='blue')
base.pack()

base.postscript("file.ps")

/Mickel
 
R

Reid Nichol

I've been dealing with the same problem. This was my solution for
saving as jpeg. You can look up how to specify gif.


# save the canvas as a ps file
self.canvas.postscript(file='tmp.ps', x=start_x, y=start_y, height=h,
width=w)

# convert the ps to a jpeg - it'll be in the middle
# of the pic
# gs = ghostscript
os.system('gs -sDEVICE=jpeg -sOutputFile=tmp.jpeg -dNOPAUSE -q -dBATCH
tmp.ps')

# extract the frame from that jpeg
# use PIL here
im = Image.open('tmp.jpeg')
box = ((im.size[0] - self.movie_size[0])/2, (im.size[1] -
self.movie_size[1])/2, (im.size[0] + self.movie_size[0])/2,
(im.size[1] + s
elf.movie_size[1])/2)
to_save = im.crop(box)

# save that extracted frame
to_save.save('ultimate_text.jpeg', 'jpeg')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top