viewing generated images

Fredrik Lundh fredrik at pythonware.com
Thu Jun 2 04:33:25 EDT 2005


Tim Flynn wrote:

>    def createWidgets(self):
>        self.image_size = (50,50)
>        self.pilim = Image.new( "1", self.image_size )
>
>        # Generate a blank image
>        f = lambda(x): 0
>        Image.eval( self.pilim, f )

I'm not sure what you think that line is doing, but it probably
doesn't do what you think it does.

try changing the Image.new call to

    self.pilim = Image.new( "1", self.image_size, 0 )

instead.

>        self.bmi = ImageTk.BitmapImage( image = self.pilim,
>                                        foreground = 'black' )

>        self.canvas = Canvas( width=100,
>                              height = 100,
>                              bg = 'white' )
>        self.quitButton = Button( self,
>                                  text="Quit",
>                                  command=self.quit )
>        self.quitButton.grid()
>        self.canvas.grid()
>        im_id = self.canvas.create_bitmap( 0,
>                                           0,
>                                           anchor = 'nw',
>                                           bitmap = self.bmi )

it's a terminology confusion: for historical reasons, Tkinter distinguishes between
bitmaps and images (this separation comes from the X window system).  Bitmap-
Image creates an image.

changing to create_image should fix the problem.

(if you're doing an image viewer, you may want to use PhotoImage
instead of BitmapImage, btw).

</F> 






More information about the Python-list mailing list