1

I found the following code for creating and drawing a scaler.

from psychopy.visual.window import Window
from psychopy.visual.slider import Slider

mywin = Window()

vection_scale = Slider(mywin,
             ticks=(1, 100),
             labels=('No Vection', 'Strong Vection'),
             granularity=1,
             color='white',
             size = (0.99,0.05))

while not vection_scale.rating:
    vection_scale.draw()
    mywin.flip()

vection_rating = vection_scale.rating
RT_rating = vection_scale.rt
print(vection_rating,RT_rating)

print(f'Rating: {vection_scale.rating}, RT: {vection_scale.rt}')

mywin.close()

The code works perfectly when mywin = Window() - when I do not put arguments to the window function.

After integrating this piece of code in my experiment code, with my window specification as shown below :

#Monitor settings
widthPix = 1400 # screen width in px
heightPix = 900 # screen height in px
monitorwidth = 53.1 # monitor width in cm
viewdist = 60. # viewing distance in cm
monitorname = 'BOE CQ LCD'
scrn = 0 # 0 to use main screen, 1 to use external screen
mon = monitors.Monitor(monitorname, width=monitorwidth, distance=viewdist)
mon.setSizePix((widthPix, heightPix))

# Create a window
win = psychopy.visual.Window(
    monitor=mon, 
    #size=(1000, 800),
    size=(widthPix,heightPix),
    color='Black',
    colorSpace='rgb',
    units='deg',
    screen=scrn,
    allowGUI=True,
    fullscr=False)

I get this error. The problem is that I need units = 'deg' to draw my stimuli.

--------------------------------------------------------------------------- KeyError                                  Traceback (most recent call last) <ipython-input-1-ebcaf2ecf00b> in <module>
    117 # ---------------------------------------- Create Scale to Rate Feeling of Vection
------------------------------------------------------------------------
    118 
--> 119 vection_scale = Slider(win,ticks=(1, 100),labels=('No Vection', 'Strong Vection'),granularity=1,color='white')
    120 
    121 # ----------------------------------------- Start Experiment ------------------------------------------------------------------------------------

~/opt/anaconda3/lib/python3.7/site-packages/psychopy/visual/slider.py in __init__(self, win, ticks, labels, pos, size, units, flip, style, granularity, readOnly, color, font, depth, name, labelHeight, labelWrapWidth, autoDraw, autoLog)
    140 
    141         if size is None:
--> 142             self._size = defaultSizes[self.units]
    143         else:
    144             self._size = size

KeyError: 'deg'

How can I overcome this obstacle? thanks in advance for your help :slight_smile:

Kathia
  • 502
  • 2
  • 7
  • 20

0 Answers0