[Tutor] GIFs Using Tkinter

Lloyd Kvam pythontutor at venix.com
Mon Sep 8 11:31:59 EDT 2003


My guess is that you did this on Windows and did not include "rb" on the
open call.  Change the recipe fragment:
	...open("icon.gif")...
to
	...open("icon.gif","rb")...

In Windows, the default mode when opening a file is "Text Mode" which
provides special handling for line mark characters, r"\r\n".  This means
that bits in your image that accidently match the line handling will get
mangled.  "rb" opens the file for reading in binary mode.  I believe that
Microsoft uses raw and cooked to differentiate the two modes of reading
files.

Gregor Lingl wrote:

> Hi all!
> 
> I'm trying to use recipe 9.5 from Python Cookbook, which suggests
> to read gifs from files using base64.encodestring in order to embed 
> those images into my sourcecode.
> 
> I've prepared some 20 gifs with Photoshop which are all merely
> rotated versions of some "master"-gif. (They all are produced in
> exactly the same way and have (255,255,255) as transparent color.)
> 
> They all can be used as Tkinter PhotoImages with the file-option
> perfectly well.
> 
> However, if I try to use the data-option with strings constructed
> from those same gifs according to the recipe mentioned above,
> I observe, that among those gif-images
> (1) some can be displayed correctly (more than 50%)
> (2) some are corrupted and are displayed with stripes or other
> artefacts.
> (3) and some result in strings only a few characters long
> which cannot be interpreted as image-data at all.
> 
> What could be the reason for this annoying behaviour and how
> can I avoid it.
> 
> Thanks in advance
> 
> Gregor
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582




More information about the Tutor mailing list