[Tutor] plotting pixels

Bill Allen wallenpb at gmail.com
Mon Sep 20 04:27:01 CEST 2010


On Sun, Sep 19, 2010 at 2:40 AM, Lie Ryan <lie.1296 at gmail.com> wrote:

>
> More slowly and takes huge amount of memory. A single Tk canvas object
> takes at least 14 words (= 114 bytes in 64-bit OS = 56 bytes in 32-bit
> OS) + the amount of data is needed to store the `kind of object`. That's
> much larger than the ideal 3 bytes per pixel (or 4 bytes with alpha).
>
> Tkinter's Canvas intentionally doesn't provide create_pixel() because
> unlike most other Canvas implementations, Tkinter's Canvas holds a
> stateful canvas objects instead of a simple drawing surface. Providing a
> create_pixel() will be too tempting for abuse, which would make the
> canvas unbearably slow and memory consuming. In short, Canvas is not
> designed for pixel drawing.
>
> > Digging a little deeper it seems the idiomatic way to do this in Python
> > is to use PIL the Python Imaging Library to create a GIF or bitmap
> > image and then insert that into Tkinters cancvas as an image object.
> >
> > The Pil ImageDraw class has a point() ethod
>
> If you need to plot pixels, do use pygame, PIL, or at least the
> PhotoImage trick.
>
> Thanks for the feedback!   That does make a lot a sense as to why a
pixel_plot() type function would not be directly implemented in Canvas.  As
this is still largely a learning exercise for me, I may try more than one
approach.  I think first I will try the PhotoImage approach, which might be
the most efficient method.  However, I will definitely give Pygame a try.  I
have seen several programs that were written in Pygame and I am really
impressed!  It is obviously designed to task.

-Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100919/c8c3d170/attachment-0001.html>


More information about the Tutor mailing list