psychopy.org | Reference | Downloads | Github

Program is not accepting mouse click

spyder
mouse
python3

#1

I trying to run below mentioned program in python spyder 3.6, 64 bit on windows 10 64 bit. When I run the code it is not accepting any mouse key. I am able to move the cursor but when I try to click on rating scale nothing is happning. What could be the problem? This code is the first part of the rating scale program in Demos. Thank you.

code: 
from __future__ import division
from __future__ import print_function

from psychopy import visual, event, core, logging
import os

# create a window before creating your rating scale, whatever units you like:
win = visual.Window(fullscr=False, size=[1100, 800], units='pix', monitor='testMonitor')
instr = visual.TextStim(win, text="""This is a demo of visual.RatingScale(). There are four examples.

Example 1 is on the next screen. Use the mouse to indicate a rating: click somewhere on the line. You   can also use the arrow keys to move left or right.

To accept your rating, either press 'enter' or click the glowing button. Pressing 'tab' will skip the rating.

Press any key to start Example 1 (or escape to quit).""")

event.clearEvents()
instr.draw()
win.flip()
if 'escape' in event.waitKeys():
    core.quit()

# Example 1 --------(basic choices)--------
# create a RatingScale object:
myRatingScale = visual.RatingScale(win, choices=['cold', 'cool', 'hot'])

# Or try this one:
# myRatingScale = visual.RatingScale(win, choices=map(str, range(1, 8)), marker='hover')

# the item to-be-rated or respond to:
myItem = visual.TextStim(win, text="How cool was that?", height=.12, units='norm')

# anything with a frame-by-frame .draw() method will work, e.g.:
# myItem = visual.MovieStim(win, 'jwpIntro.mov')

event.clearEvents()
while myRatingScale.noResponse:  # show & update until a response has been made
    myItem.draw()
myRatingScale.draw()
win.flip()
if event.getKeys(['escape']):
    core.quit()

print('Example 1: rating =', myRatingScale.getRating())
print('history =', myRatingScale.getHistory())

when I press ‘escape’ key, the window is not closing. I am also putting the trace back.

runfile('C:/Users/ravikumar.mevada/Gustometer/qmix/examples/rating2.py', wdir='C:/Users/ravikumar.mevada/Gustometer/qmix/examples')
An exception has occurred, use %tb to see the full traceback.

SystemExit: 0

c:\program files\python36\lib\site-packages\IPython\core\interactiveshell.py:2971: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

#2

Is the indenting as you show it here? If so it’s clear what’s happening. You need to make sure the win.flip() command and the escape if-condition are part of the while loop. So, like this:

event.clearEvents()
while myRatingScale.noResponse:  # show & update until a response has been made
    myItem.draw()
    myRatingScale.draw()
    win.flip()
    if event.getKeys(['escape']):
        core.quit()

win.flip() is what actually lets PsychoPy check for events. Calling “draw” just adds the item to the draw buffer, it doesn’t actually render it. In fact it shouldn’t even be drawing your rating scale with the code as written, it should get through the instructions and then just freeze.