Two windows instead of one?

Hello everybody,

Using the psychopy.visual module to draw a window with a certain image as per the code below in PyCharm. For some reason I am getting two windows as opposed to one. I’ve reinstalled Python and all the associated packages but it still spits out this same error. I’ve followed all the instructions for the manual install as per http://psychopy.org/installation.html with no errors at all, so not sure why this may be happening.


from psychopy import visual
from psychopy import event

win_one = visual.Window(
     size=[400, 400],
     units="pix",
     fullscr=False,
     color=[1,1,1]
)

img = visual.ImageStim(
    win=win_one,
    image="/Users/rpuri/Desktop/UNSW.png",
    units="pix"
)

img.draw()

win_one.flip()

event.waitKeys()

win_one.close()

The output in the console is as follows,

1.2233 	WARNING 	Monitor specification not found. Creating a temporary one...
1.3358 	WARNING 	Monitor specification not found. Creating a temporary one...
Exception AttributeError: "'NoneType' object has no attribute 'glDeleteLists'" in <bound method ImageStim.__del__ of <psychopy.visual.image.ImageStim object at 0x10e069b50>> ignored

I would really appreciate any help and advice, thank you!

My guess is it might be a filename issue. Maybe try renaming the file to something unusual and see if that helps?

You would get the behaviour you describe if something else is ‘importing’ your file.

Otherwise, you should also be able to get around it (though the import issue will remain) by putting everything except your imports indented under a if __name__ == "__main__": test. I.e.:

from psychopy import visual
from psychopy import event

if __name__ == "__main__":

    win_one = visual.Window(
         size=[400, 400],
         units="pix",
         fullscr=False,
         color=[1,1,1]
    )

    img = visual.ImageStim(
        win=win_one,
        image="/Users/rpuri/Desktop/UNSW.png",
        units="pix"
    )

    img.draw()

    win_one.flip()

    event.waitKeys()

    win_one.close()
1 Like

Wow, thanks djmannion, both your solutions worked!

I changed the name from ‘Image.py’ to something more unusual and it worked! Using the if __name__ == "__main__": worked as well.

Cheers

Cool, glad that it worked. Changing the filename is the best strategy - putting the code inside the if statement only hides the problem (other code would be expecting different functionality to be provided by Image).

Cheers,

Damien.