Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > saving a tkinter canvas to gif

Reply
Thread Tools

saving a tkinter canvas to gif

 
 
biner
Guest
Posts: n/a
 
      04-14-2004
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.

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Mickel_Gr=F6nroos?=
Guest
Posts: n/a
 
      04-15-2004
On Wed, 14 Apr 2004, biner wrote:

> 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

--
Mickel Grönroos, application specialist, linguistics, Research support, CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi

 
Reply With Quote
 
 
 
 
Reid Nichol
Guest
Posts: n/a
 
      04-16-2004
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')


(biner) wrote in message news:<. com>...
> 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.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to couper contenier of a canvas in an outer canvas??? olsr.kamal@gmail.com Python 10 03-15-2013 08:46 PM
saving lines on canvas as GIF file format Andy Cho Java 4 08-18-2009 11:56 PM
Canvas with scrollbars - how to get correct canvas coordinate when the scroll bars have moved? PhilC Python 2 10-25-2004 11:57 AM
Canvas scrolling - scrollBar become "disabled" on change in canvas Askari Python 2 08-30-2004 02:56 PM
Re: saving a tkinter canvas =?ISO-8859-1?Q?Mickel_Gr=F6nroos?= Python 0 04-01-2004 06:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57