473,543 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.createWidg ets()

def createWidgets(s elf):
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.BitmapI mage( image = self.pilim,
foreground = 'black' )
self.canvas = Canvas( width=100,
height = 100,
bg = 'white' )
self.quitButton = Button( self,
text="Quit",
command=self.qu it )
self.quitButton .grid()
self.canvas.gri d()
im_id = self.canvas.cre ate_bitmap( 0,
0,
anchor = 'nw',
bitmap = self.bmi )
viewer = Viewer()
viewer.master.t itle("Test viewer")
viewer.mainloop ()

The create_bitmap call fails with the following error :

_tkinter.TclErr or: 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 2359
Tim Flynn wrote:
def createWidgets(s elf):
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.BitmapI mage( image = self.pilim,
foreground = 'black' ) self.canvas = Canvas( width=100,
height = 100,
bg = 'white' )
self.quitButton = Button( self,
text="Quit",
command=self.qu it )
self.quitButton .grid()
self.canvas.gri d()
im_id = self.canvas.cre ate_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(s elf):
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.BitmapI mage( image = self.pilim,
foreground = 'black' )

self.canvas = Canvas( width=100,
height = 100,
bg = 'white' )
self.quitButton = Button( self,
text="Quit",
command=self.qu it )
self.quitButton .grid()
self.canvas.gri d()
im_id = self.canvas.cre ate_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
2581
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 (that part's not here -- spotlighting the problem code): --------BEGIN CODE PAGE------------ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
13
3024
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 size in browser settings). When someone does that, the layers seem to overlap and the layer with a greater z value pops in front and the other layers...
5
2718
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
1009
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
1434
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, it re-draws the rest of the page below it. Some times it enlarges in the area below the current image which makes the mouse cursor no longer over...
1
1924
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 and off.
10
5286
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
1514
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 of the database components. Yet, when I switch to code view, I can see everything just fine. Does anyone have any idea why the Data Sources window...
5
3824
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 show various countries appearing to be depressed when "moused-over". To keep it simple at first, I just decided to try two countries. After copying...
0
7397
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7336
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7582
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7675
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3384
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3385
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1809
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.