Generating a spacer gif on the fly

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Wed Oct 9 06:50:15 EDT 2002


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 *


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




if __name__=="__main__":
    root=Tk()
    image=Spacer(color="black", width=10, height=10)
    l=Label(root, image=image.getSpacer())
    l.pack()
    root.mainloop()


-- 
### Python Powered Signature
I started writting this email on 
Wed Oct  9 10:43:32 2002





More information about the Python-list mailing list