In an earlier reply to this post (April 29), I described how to embed
XBM images in Python code for use with Tkinter. Here's some code that
allows you to embed also GIF files in a Python script, using an un-
documented feature in recent Tk versions. I've tested this with Tk
8.0, but I think it works with Tk 4.2 as well:
from Tkinter import *
root = Tk()
# must initialize Tkinter before importing image!
import myimage
Label(root, image=myimage.image).pack()
root.mainloop()
You may of course cut and paste instead of importing the image modules
(and if you have PIL, consider using image2py instead).
Enjoy /F (http://hem1.passagen.se/eff)
--------------------------------------------------------------------
#
# gif2tk.py
#
# convert GIF file to Python module defining a Tkinter PhotoImage
#
import base64, sys
if not sys.argv[1:]:
print "Usage: gif2tk.py giffile >pyfile"
sys.exit(1)
data = open(sys.argv[1], "rb").read()
if data[:4] != "GIF8":
print sys.argv[1], "is not a GIF file"
sys.exit(1)
print '# generated from', sys.argv[1], 'by gif2tk.py'
print
print 'from Tkinter import PhotoImage'
print
print 'image = PhotoImage(data="""'
print base64.encodestring(data),
print '""")'
--------------------------------------------------------------------