[Image-SIG] Twiddle screen pixels

Fredrik Lundh fredrik@pythonware.com
Thu, 2 Dec 1999 01:11:44 +0100


Stephen J King <king@calibre-dd.com> wrote:
> Forgive a relative PIL newbie if this is a trivial matter, but:
> 
> I want to use PIL as a framework for testing image processing algorithm
> prototypes written in python. I am trying to write something which will
> continuously update the screen image as data is generated. I've modified
> one of the PIL demos to this:

unfortunately, in the process of modifying the demo, you
removed all code involved in actually displaying the image...

> #
> # painter widget
> 
> class PaintCanvas(Canvas):
>     def __init__(self, master, image):
>                 Canvas.__init__(self, master, width=image.size[0],
> height=image.size[1])
>                 self.image = image
>                 self.bind("<B1-Motion>", self.paint)
> 
>     def paint(self, event):
>                 xy = event.x, event.y
>                 try:
>                         self.image.putpixel(xy,0)
>                 except:
>                         pass
>                 self.update_idletasks()
> 
> #
> # main
> 
> root = Tk()
> 
> size=(250,250)
> im = Image.new('RGB',size)
> 
> PaintCanvas(root, im).pack()
> 
> root.mainloop()
> 
> ###

I'd suggest you take another look at the original script,
and that you keep the important pieces.  if you want
to start with something simpler, use viewer.py instead
of painter.py

(but don't forget that painter.py uses tiling for a
reason -- see the comments in that file for details).

> I would rather not use tiling, as this would add an
> unnecessary layer of complexity.

why?  I mean, I've already written the code for you :-)

</F>