| Reference | Downloads | Github

Exit button --> end loop

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

OS (e.g. Win10): macOS Catalina Version 10.15.1
PsychoPy version (e.g. 1.84.x): Psychopy v.3.1.5
Standard Standalone? (y/n) If not then what?: mac

What are you trying to achieve?: exit the loop after clicking on exit button
In my experiment I have two routines in the same loop (you can imagine it as two trials with different levels of difficulty, trial1 and trial2, “trials” is the name of the loop) and after that, I have one ‘Feedback’ routine. In both trials you have an “exit” button on which you can click if you want to stop the trials and go directly to the feedback routine.

What did you try to make it work?: I have the following code for the exit button:

in the tab “Begin routine”:
ExitButton = visual.ButtonStim(win, labelText= “Exit”, pos=(0, -.28))
ExitButton.buttonEnabled = True

in the tab “each frame”
if ExitButton.buttonSelected:
continueRoutine = False
trials.finished = True

What specifically went wrong when you tried that?: This code works in the seconde routine (the one just before the feedback routine) but not in the first one. If I click on the exit button in the first routine I only end the routine and go to the next routine (trial2) but it does not quit the loop and go to the feedback routine.

Hey @aelreym, same problem here, did you figure things out?

@Oceane. @aelreym, the method to end loops online has been fixed in version 2020.1, and the correct method for ending loops using JavaScript code is the following - in this example we end the loop when the current loop iteration (nReps) is 2:

// this conditional can be whatever you want, this is just an example
if (currentLoop.thisRepN == 2)   
    trials.finished = true;

Note, this will only work from PsychoPy version 2020.1 onwards.


@dvbridges, I did the update and now I cannot open psychopy anymore. When I want to open psychopy it shows me an error message and “open console” or “terminate”.

@aelreym, try the troubleshooting suggestions, you may just need to clear your user and app data config files.

@dvbridges, I was not able to resolve this with the troubleshooting suggestions but I don’t understand every suggestion there. But in the terminal program I pasted the following message: /Applications/ -m
AND I got this error message: /Applications/ Error while finding module specification for ‘’ (ModuleNotFoundError: No module named ‘psychopy’)
Do you know what I should do?