Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > tkinter photoimage, couldn't recognize image data (PPM)

Reply
Thread Tools

tkinter photoimage, couldn't recognize image data (PPM)

 
 
Martin P. Hellwig
Guest
Posts: n/a
 
      12-09-2009
Hi all,

I've tried to display an image with the source being a string but it
fails (see below). Is there a way to display PPM without writing it
first to a file?

Thanks,

Martin

----- snippet -----
'''
Ubuntu 9.04 64bit, python 3.1
'''
import tkinter

DATA="""P3
3 2
255
255 0 0 0 255 0 0 0 255
255 255 0 255 255 255 0 0 0"""

def display():
tk = tkinter.Tk()
canvas = tkinter.Canvas(tk, width=3, height=2)
canvas._image_reference = tkinter.PhotoImage(format='ppm', data=DATA)
canvas.create_image((0,0), image=canvas._image_reference)
canvas.pack()
tk.after(1500, tk.quit)
tk.mainloop()

if __name__ == '__main__':
display()
-----

----- traceback -----
Traceback (most recent call last):
File "/home/martin/DCUK
Technologies/workspace/mhellwig/src/test/tkintering.py
", line 24, in <module>
display()
File "/home/martin/DCUK
Technologies/workspace/mhellwig/src/test/tkintering.py
", line 17, in display
canvas._image_reference = tkinter.PhotoImage(format='ppm', data=DATA)
File "/usr/local/lib/python3.1/tkinter/__init__.py", line 3269, in
__init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/usr/local/lib/python3.1/tkinter/__init__.py", line 3225, in
__init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize image data
-----

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      12-09-2009
Martin P. Hellwig wrote:
> Hi all,
>
> I've tried to display an image with the source being a string but it
> fails (see below). Is there a way to display PPM without writing it
> first to a file?
>
> Thanks,
>
> Martin
>
> ----- snippet -----
> '''
> Ubuntu 9.04 64bit, python 3.1
> '''
> import tkinter
>
> DATA="""P3
> 3 2
> 255
> 255 0 0 0 255 0 0 0 255
> 255 255 0 255 255 255 0 0 0"""


Should the string really have the newlines? Or should this be
DATA="""P3\
3 2\
255\
255 0 0 0 255 0 0 0 255\
255 255 0 255 255 255 0 0 0"""

> def display():
> tk = tkinter.Tk()
> canvas = tkinter.Canvas(tk, width=3, height=2)
> canvas._image_reference = tkinter.PhotoImage(format='ppm', data=DATA)
> canvas.create_image((0,0), image=canvas._image_reference)
> canvas.pack()
> tk.after(1500, tk.quit)
> tk.mainloop()
>
> if __name__ == '__main__':
> display()
> -----
>
> ----- traceback -----
> Traceback (most recent call last):
> File "/home/martin/DCUK
> Technologies/workspace/mhellwig/src/test/tkintering.py
> ", line 24, in <module>
> display()
> File "/home/martin/DCUK
> Technologies/workspace/mhellwig/src/test/tkintering.py
> ", line 17, in display
> canvas._image_reference = tkinter.PhotoImage(format='ppm', data=DATA)
> File "/usr/local/lib/python3.1/tkinter/__init__.py", line 3269, in
> __init__
> Image.__init__(self, 'photo', name, cnf, master, **kw)
> File "/usr/local/lib/python3.1/tkinter/__init__.py", line 3225, in
> __init__
> self.tk.call(('image', 'create', imgtype, name,) + options)
> _tkinter.TclError: couldn't recognize image data
> -----
>


 
Reply With Quote
 
 
 
 
Martin P. Hellwig
Guest
Posts: n/a
 
      12-09-2009
Terry Reedy wrote:
<cut>
>> DATA="""P3
>> 3 2
>> 255
>> 255 0 0 0 255 0 0 0 255
>> 255 255 0 255 255 255 0 0 0"""

>
> Should the string really have the newlines? Or should this be
> DATA="""P3\
> 3 2\
> 255\
> 255 0 0 0 255 0 0 0 255\
> 255 255 0 255 255 255 0 0 0"""
>


I've tried it, still same error, I did had a look at
http://netpbm.sourceforge.net/doc/ppm.html and the wikipedia page.

<cut>
>> self.tk.call(('image', 'create', imgtype, name,) + options)
>> _tkinter.TclError: couldn't recognize image data
>> -----
>>

>



--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read image data into Tkinter Canvas? Frederic Rentsch Python 0 03-03-2012 04:10 PM
tkinter, loading image error, TclError: couldn't recognize data in defn noob Python 2 06-30-2008 09:26 AM
[OpenCV] Extract en recognize barcode from image file. kurapix@gmail.com C Programming 5 04-11-2008 02:43 AM
Acronis True Image 8.0 boot media wont recognize USB mouse Father Ted Crilly Computer Support 3 04-19-2007 11:05 AM
Does any one recognize this binary data storage format geskerrett@hotmail.com Python 27 10-05-2005 08:24 AM



Advertisments