Set the position of the written response at pre-determined positions

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v1.90.2 and also PsychoPy 2020.1.3
Standard Standalone? (y/n) If not then what?: Yes
What are you trying to achieve?:
I am trying to set the position of the responses typed with the keyboard at pre-determined positions. Here is the task: Observers are presented with a stimulus for 10 seconds, they need to press a key whenever they detect a change in the stimulus. When the trial is finished, these key presses are shown as white bars on a long line representing the duration of the trial (see below).


Now, they need to write their key responses on these white bars (as shown below).

But I cannot set the position of the typed responses separately. They appear altogether at all positions (as shown below).

What did you try to make it work?: Here is what I did to set the position of the written response:

    for position in positions: # 'positions' is the list of positions for written response
        writtenText.pos = (position ,50) 
        writtenText.text = "".join(response.keys) #'response.keys' is the keys they press (2, 3, 4 ...)
        writtenText.draw()

Hi There,

I think you might want something like the below:

for i in range(response.keys): # 'positions' is the list of positions for written response
    writtenText.pos = (position[i] ,50) 
    writtenText.text = "%s"%(response.keys[i]) #'response.keys' is the keys they press (2, 3, 4 ...)
    writtenText.draw()

Here you set the position AND text on each iteration of the for loop. In your previous example there you iterate through a list of positions and set the position on each iteration, but the text is the same on each iteration (which is why you can joined “234” at each position )

Hope this helps!
Becca

Thanks a lot for you response!

Here, I think there is a typo: writtenText.pos = (position[i] ,50)
So I changed it as: writtenText.pos = (positions[i] ,50)

Then, I run the code, but this error occurred:

for i in range(response.keys): # ‘positions’ is the list of positions for written response
TypeError: ‘list’ object cannot be interpreted as an integer

So I removed range():

    for i in response.keys: # 'positions' is the list of positions for written response
        writtenText.pos = (positions[i] ,50) 
        writtenText.text = "%s"%(response.keys[i]) #'response.keys' is the keys they press (2, 3, 4 ...)
        writtenText.draw()

But now this error occurred:
writtenText.pos = (positions[i] ,50)
TypeError: list indices must be integers or slices, not str

I would really appreciate if you can tell me what is wrong!

Best,
Zeynep

Hi,

Try changing range to len.

Becca

Hi again,

It immediately gives this error :frowning:

for i in len(response.keys): # ‘positions’ is the list of positions for written response
TypeError: ‘int’ object is not iterable

This solved it:

    for i in range(len(response.keys)): # 'positions' is the list of positions for written response
        writtenText.pos = (positions[i] ,50) 
        writtenText.text = "%s"%(response.keys[i]) #'response.keys' is the keys they press (2, 3, 4 ...)
        writtenText.draw()

Thanks so much!

Best,
Zeynep

1 Like

oops - my bad sorry! third time lucky hopefully

range(len(response.keys))