[Tutor] Available filetypes for AskSaveasfilenam in Tkinter?

John Fouhy john at fouhy.net
Fri Jan 23 04:03:23 CET 2009

2009/1/23 Wayne Watson <sierra_mtnview at sbcglobal.net>:
> Continuing.  The code that is eventually used to do the save is:
> ===================
>     def SaveGIF(self):
>         if self.current_path:
>             default_path = splitext(basename(self.current_path))[0] + ".gif"
>             path = asksaveasfilename(defaultextension=".gif",
>                                      title="Save as GIF",
>                                      initialfile=default_path,
>                                      filetypes=GIF_FILE_TYPES)
>         else:
>             path = asksaveasfilename(defaultextension=".gif",
>                                      title="Save as GIF",
>                                      filetypes=GIF_FILE_TYPES):
>         if not path:
>             return
>         gif = self.current_image.convert("RGB")
>         gif.save(path)
> ==================
> I would think convert makes the conversion. If so, then it must know a lot
> of formats. How do I know which ones it has available? If it has a small
> set, is there some way to find another "convert" that produces, say, a 'pcx"
> formated file.
> Apparently, "RGB" and "GIF" mean the same thing. Seems a bit odd.

Well, "RGB" stands for "Red Green Blue".  I'm not much of a graphics
format guy, but I think it means basically a bitmap, where each pixel
has an associated tuple (red, green, blue) containing the proportion
of each (on a range from 0..255).
(as opposed to vector formats like EPS, or layered formats that
programs like photoshop use)

It is possible that the save() function inspects the file name
extension and produces output appropriately.

At any rate, your question seems more to do with the image library you
are using, and nothing at all to do with tkFileDialog.asksaveasformat.
It's probably PIL -- the Python Image Library.  See the documentation
here: http://www.pythonware.com/library/pil/handbook/index.htm


More information about the Tutor mailing list