Generating a spacer gif on the fly

Martin Franklin mfranklin1 at
Wed Oct 9 13:21:56 CEST 2002

On Wednesday 09 Oct 2002 10:50 am, Martin Franklin wrote:
> On Wednesday 09 Oct 2002 9:36 am, Max M wrote:
> > Hi
> >
> > I am writing an app where it would be practical to have a function that
> > generates a spacer gif in a given color::
> >
> >      def spacer(color=''):
> >          "Generates a 1x1 pixel gif with color, no color means
> > transparent"
> Guessing that you are using Tkinter.......  try the PhotoImage class:-
> from Tkinter import *

<snip my own dodgy looking code....>

### tested'ish

from Tkinter import *

class Spacer:
    def __init__(self, color="", width=1, height=1):        
        self.image = PhotoImage(width=width, height=height)
        if color:
            for row in range(height):
                for col in range(width):
                    self.image.put(color, (col, row))
    def getSpacer(self):
        return self.image

if __name__=="__main__":
    image=Spacer(width=100, height=10, color="red")
    l1=Label(root, text="Image here>")
    l=Label(root, image=image.getSpacer())
    l1=Label(root, text="<Image here")

## notes:  doing it in a class like this takes care of the referencing of the
## image (python cleans up un-referencd Tk images.....)

### Python Powered Signature
I started writting this email on 
Wed Oct  9 11:18:04 2002

More information about the Python-list mailing list