psychopy.org | Reference | Downloads | Github

Stimuli don't appear on the screen

screen

#1

Hello everyone,

I’m working on a simple question-answering experiment.

I think the code is fine, but when I run it the screen shows up and nothing happens. Just a blank screen.

def subjective_value_rating(window, level_value):

    # Variable setup
    main_inst = visual.TextStim(win=window, text='test',
                                color='white', bold=True, pos=(0.0, 2.0))
    sub_values = level_value
    levels = sub_values.keys()
    value_low = 2000
    change_ratio = 1
    text_low = str(value_low)+'Won\n level 1' 
    option_high = visual.TextStim(win=window, text='', 
                                  color='white', pos=(-3, -1))
    option_low = visual.TextStim(win=window, text=text_low, 
                                 color='white', pos=(3, -1))
    # 1: high effort/amount (value up), 2: low effort/amount (value down) 
    keyList = ['escape', '1', '2']
    
    # Run trials
    for level in levels:  # Loop by effort levels; 0.2/0.4/0.6/0.8
        # Update high effort condition text
        option_high.text = str(sub_values[level])+'Won\n level '+level 
        
        for i in range(6): 
            # Draw stimuli
            event.clearEvents()
            main_inst.draw()
            option_high.draw()
            option_low.draw()
            window.flip()

            # Get key response
            key = event.waitKeys(keyList=keyList)
            if key == 'escape':
                core.quit()
            elif key == '1':  # If high effort/amount chosen,
                sub_values[level] = sub_values[level] + (1000 * change_ratio/2)
                window.flip()
            elif key == '2':  # If low effort/amount chosen,
                sub_values[level] = sub_values[level] - (1000 * change_ratio/2)
                window.flip()
            
            change_ratio = change_ratio/2
    
    return sub_values

# Test
from psychopy import monitors

my_monitor = monitors.Monitor(name='test_monitor')
my_monitor.setSizePix((800, 600))
my_monitor.setWidth(30)
my_monitor.setDistance(60)
my_monitor.saveMon()
win = visual.Window(monitor=my_monitor, unit='deg', fullscr=False,
                    color='black')

subVals = {'0.2': 1000, '0.8': 1000}
subValDict = subjective_value_rating(win, subVals)

I came up couple of causes to this problem: text stimuli, screen setups
So I tried to fix these, but it was same.
I think the unknown problem happens before the second for loop, given that on the screen no keys I specified in the key lists do not work.

Any advice to fix this code would be appreciated.


#2

A couple of issues:

  1. It looks like TextStim need the units to be set explicitly (i.e. units='deg'), rather than being inherited from the units of the window.
  2. event.waitKeys returns a list rather than a single value, so none of the if or elif statements will be true. The easiest change would be to use key = event.waitKeys(keyList=keyList)[0].

#3

@djmannion

Yeah you are right. The code runs perfectly now. Thank you!:slight_smile: