Image open problem

A

Aleksandar Cikota

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.Telescope')

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

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.Application')

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
 
J

John Machin

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.<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.
 
J

John McMonagle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,134
Latest member
Lou6777736
Top