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 2 2374
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>
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 Transitional//EN"
|
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 are pushed back.
The most obvious solution will be to prevent the user from increasing
the text...
|
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" %>
|
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
|
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 the image so the
onmouseout (which reverts the image back to the original thumbnail size)
occurs...
| |
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.
|
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
|
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 becomes disabled when
I'm viewing forms?
TIA.
|
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 the HTML and JavaScript codes generated by ImageReady into the page I wanted to insert the map into,...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |