| Reference | Downloads | Github

I need to know the time of presentation of my stimuli


If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win 7
PsychoPy version (e.g. 1.84.x): 1.83
Standard Standalone? (y/n) If not then what?: Standalone

Hi there! I’m using the builder view to design an experiment that goes like this:

  1. Fixation cross (1 s)
  2. Stimulus (7 s)
  3. Fixation cross (jittered, 6 to 10 s)
  4. Question (4 s)

All these elements are inside a loop, each one represented by a routine, and a text component inserted within that corresponding routine. In the case of the stimulus, the name of the routine is “Estimulo” and the name of the text component is “Medio” (Spanish).

I need to know the exact time when the stimulus is presented. The default .csv output file doesn’t contain this information, and I would like you to tell me if you know a way to get it.

Thanks a lot!


Hello Alan,
I think you can find this information in the experiment log file.
It might not be handy to extract though. Another way is to insert a code component into the routine and add the code to store what you need in the data file. Have a look at



Hi Luca,

Similar to Alan I want to record onset and offset times of each stimulus in my experiment. This information is in the log file, but like you said that is difficult to extract. In terms of using exp.addData() to add this information to my csv file, what do I call the onset and offset times, i.e. what does in the parentheses of this line?

Also, would I just put the code component with this information right after the image component in my builder?

Thank you!!


Hi Sarah, let me make an example. So imagine that you want to record the onset and offset time of a text component which starts at the beginning of the routine and ends 1 second after. If you look at the python code that is generated out of the builder script, you get:

while continueRoutine and routineTimer.getTime() > 0: # get current time t = trialClock.getTime() frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # text updates if t >= 0.0 and text.status == NOT_STARTED: # keep track of start time/frame for later text.tStart = t text.frameNStart = frameN # exact frame index text.setAutoDraw(True) frameRemains = 0.0 + 1.0- win.monitorFramePeriod * 0.75 # most of one frame period left if text.status == STARTED and t >= frameRemains: text.setAutoDraw(False) # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in trialComponents: if hasattr(thisComponent, “status”) and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # check for quit (the Esc key) if endExpNow or event.getKeys(keyList=[“escape”]): core.quit() # refresh the screen if continueRoutine: # don’t flip if this routine is over or we’ll get a blank screen win.flip()

So you know that the onset time is stored in text.tStart.You can add the instruction to get the offset time:

if text.status == STARTED and t >= frameRemains: text.setAutoDraw(False) text.tEnd = t

Then to save the value in the data file:

exp.addData(‘TextOnset’, text.tStart)exp.addData(‘TextOffset’, text.tEnd)

You might want to look at all the different components to see if they provide a more accurate timing procedure and maybe refer to that one.Did I answer to the question?



Hi Luca,

This is really useful. I’m having issues placing the

exp.addData(‘TextOnset’, text.tStart)

Command into the code. It does not seem to like it. In the example you give where would it be best to place this to get the required data into the excel file.



Hi Luca,

Thanks - that is useful. I will try to implement this and post again if I have a problem. Thank you!

Richard are you using the builder or the coder? I am also going to be figuring out where to place this in a code component within a routine, so if I can get that to work I will write back to try to help you.



Hi Richard,

Are you still having trouble with this? I was able to have success by using the coder instead of a code componnent in the builder.