473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

viewing generated images

Hi,

I'm trying to write a simple image viewer using Tkinter and ImageTk from
the PIL toolkit. The images are stored in memory and I don't want to
create temporary files for them.

My code looks like this :
from Tkinter import *
import Image
import ImageTk

class Viewer(Frame):
def __init__( self, master=None ):
Frame.__init__( self, master )
self.grid()
self.createWidgets()

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 )

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 )
viewer = Viewer()
viewer.master.title("Test viewer")
viewer.mainloop()

The create_bitmap call fails with the following error :

_tkinter.TclError: bitmap "pyimage2" not defined

I've seen a couple of mentions of this problem but with no solution given
other than to write the image to a temporary file, which I don't want to
do.

I'd appreciate it if anyone could point me to a different approach for
this that works (and doesn't involve creating temporary files). I'd be
open to trying a different GUI/imaging package if anyone has suggestions
for one that would be better suited to this sort of application.

Otherwise I'm also interested if anyone has any ideas about the root cause
of this problem because if I don't find some work around I intend to try to
fix it in Tkinter.

Thanks,
Tim
Jul 19 '05 #1
2 2351
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>

Jul 19 '05 #2
Fredrik Lundh wrote:
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>


That fixed the problem I was having and your right I was confused about
how to create the image but I'm sure I'll be able to figure that out now
that I'm getting some output.

Thanks much.

Tim

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
13
by: murali | last post by:
Hello everyone, I used absolute positioning with div tag in my website. The page looks cool as long as someone doesn't try to zoom in by increasing the text size (ctrl++ or thru changing font...
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
2
by: Tony Moaikel | last post by:
Hi everybody, Is there a way to view the code generated for the partial page class in ASP.NET in VS2005? Thanks, Tony
1
by: Gary | last post by:
Is it possible to have a "floating" area designated to show an enlarged image of a thumbnail? Right now I'm using a script to enlarge the image, where it's at, onmouseover, but when it enlarges,...
1
by: QLD_AU | last post by:
I am having trouble when viewing the code behind a form, any events i do are shown, however the Windows Form Designer generated code Section is not shown, Does anyone know how to turn this on...
10
by: NH | last post by:
I have a girdview with paging enabled. How can I add a message in the footer to say "Viewing records 1-15 of 45" etc Thanks
10
by: David Lee Conley | last post by:
When I open the Data Sources window and create a new data source, everything works fine. But if I have a form showing in the IDE, the Data Sources window becomes disabled and doesn't display any...
5
by: NuberSteve | last post by:
I'm very new to using CSS and also the concept of slices for mouse-overs, and have made my first attempt at using ImageReady to generate slices of a world map. I basically wanted a map that would...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.