470,600 Members | 1,466 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,600 developers. It's quick & easy.

Image open problem

Hi all,

I have a problem with openning of an image.

Here is the Code:

from Tkinter import *
from PIL import Image, ImageTk
from win32com.client import gencache
import tkMessageBox
import win32com.client
import math
import time
import os
import threading
import pythoncom

chsr = win32com.client.Dispatch("DriverHelper.Chooser")
chsr.DeviceType = "Telescope"
scopeProgID = chsr.Choose("scopeProgID")
Scope = win32com.client.Dispatch(scopeProgID)

#Scope = win32com.client.dynamic.Dispatch('ScopeSim.Telesco pe')

Document = win32com.client.Dispatch('MaxIm.Document')
FM = win32com.client.Dispatch('FocusMax.FocusControl')
CCDCamera = win32com.client.Dispatch('MaxIm.CCDCamera')
Application = win32com.client.dynamic.Dispatch('MaxIm.Applicatio n')

root = Tk()

class TestThread (threading.Thread):
def __init__(self):
threading.Thread.__init__(self, name='TestThread')
def run (self):
pythoncom.CoInitialize()
try:

Document = win32com.client.Dispatch('MaxIm.Document')
FM = win32com.client.Dispatch('FocusMax.FocusControl')
CCDCamera = win32com.client.Dispatch('MaxIm.CCDCamera')
Application =
win32com.client.dynamic.Dispatch('MaxIm.Applicatio n')

path_to_watch = "F:/Images/VRT/"
before = dict ([(f, None) for f in os.listdir (path_to_watch)])
while 1:
time.sleep(2)
after2 = dict ([(f, None) for f in os.listdir (path_to_watch)])
added = [f for f in after2 if not f in before]
if added:
name= ' ,'.join (added)
if str(name[-3:])=='fit':
print name
Document.OpenFile('F:/Images/VRT/'+name)
Document.SaveFile('F:/Images/VRT/'+
str(name[0:-4])+'.jpg', 6, 512,2)
Document.SaveFile('F:/Images/VRT/lastimage.jpg',
6, 512,2)
Application.CloseAll()

image = Image.open('G:/Robot teleskop/VRT/'+
str(name[0:-4])+'.jpg')
photo = ImageTk.PhotoImage(image)
Label(image=photo).grid(row=0, column=10,
columnspan=15, rowspan=29, sticky=W+E+N+S, padx=5, pady=5)

before = after2
finally:
try:
pythoncom.CoUninitialize()
except:
pass
TestThread().start()
#[CUT]
root.mainloop()
The error message:
Exception in thread TestThread:
Traceback (most recent call last):
File "C:\Program Files\Python\lib\threading.py", line 442, in __bootstrap
self.run()
File "G:\Robot teleskop\VRT\soft\GUI.py", line 60, in run
image = Image.open('G:/Robot teleskop/VRT/'+ str(name[0:-4])+'.jpg')
AttributeError: 'function' object has no attribute 'open'
I think the modul is not imported how it should be. I hope for help.
Thanks!

Regards,
Aleksandar
Apr 19 '06 #1
2 4271
On 20/04/2006 6:55 AM, Aleksandar Cikota wrote:
Hi all,

I have a problem with openning of an image.

Here is the Code:

from Tkinter import *
from PIL import Image, ImageTk
Insert here:
print type(Image), type(Image.open), Image.version

Here are my results:
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
from PIL import Image, ImageTk
Image.VERSION '1.1.5' type(Image) <type 'module'> type(Image.open)

<type 'function'>

.... which is what I expected

[snip]

If the print statement gives incorrect results, I'd advise re-installing
PIL.
If it gives correct results, add a copy of the print further towards
where the error occurs. Binary search until you have found the culprit
that is mangling Image.

image = Image.open('G:/Robot teleskop/VRT/'+
str(name[0:-4])+'.jpg')
I thought I'd already seen somebody point out to you that all those
str() calls are rather redundant ...
[snip]>
The error message:
Exception in thread TestThread:
Traceback (most recent call last):
File "C:\Program Files\Python\lib\threading.py", line 442, in __bootstrap
self.run()
File "G:\Robot teleskop\VRT\soft\GUI.py", line 60, in run
image = Image.open('G:/Robot teleskop/VRT/'+ str(name[0:-4])+'.jpg')
AttributeError: 'function' object has no attribute 'open'
The implication is that Image is a function, which is weird.

I think the modul is not imported how it should be. I hope for help.


Apr 20 '06 #2
On Thu, 2006-04-20 at 10:29 +1000, John Machin wrote:
On 20/04/2006 6:55 AM, Aleksandar Cikota wrote:
Hi all,

I have a problem with openning of an image.

Here is the Code:

from Tkinter import *
from PIL import Image, ImageTk


Change from PIL import Image, ImageTk to import PIL and change all your
corresponding Image calls to PIL.Image and all your ImageTk calls to
PIL.ImageTk.

If that works, then something else is mangling Image.

Regards,

John

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Apr 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by D. Alvarado | last post: by
4 posts views Thread by moondaddy | last post: by
7 posts views Thread by lgbjr | last post: by
3 posts views Thread by den 2005 | last post: by
14 posts views Thread by Steve K. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.