Adding interword interval (ISI) with word-by-word sentence presentation

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2022.2.3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:

Hi everyone! I am programming an EEG experiment where sentences of varying length will be presented word by word with (and this is where it got tricky for me) a picture of the speaker above them. Each word is supposed to be presented for 200 ms + additional 30 ms per each letter. Importantly, however, I need a 500 ms interword interval during which the picture of the speaker must stay on the screen but no word will be shown.
I managed to achieve word-by-word presentation together with the picture but without the interword interval using this code:

Begin Routine
words = sentence.split()
numWords = len(words)
i = 0
frameCounter = 0

Each Frame
if i <= numWords-1:
text.setText(words[i])
frameCount = 29 + (len(words[i].split()) * int(0.03*144)) # my screen runs at 144 Hz, so 29 frames is about 200 ms, etc.
frameCounter+=1
if frameCounter == frameCount:
i+=1
frameCounter = 0
else:
continueRoutine = False

So my problem is adding the interword interval (500ms). I know I need to somehow add text.setText(" ") displaying for 72 frames but I can’t figure out how to do it. Any help will be greatly appreciated

How about this?

Begin Routine

words = sentence.split()
numWords = len(words)
i = 0
frameCounter = 0
showISI = False 

Each Frame

if i <= numWords-1:
    if not showISI:
        text.setText(words[i])
        frameCount = 29 + (len(words[i].split()) * int(0.03*144)) 
        frameCounter+=1
        if frameCounter == frameCount:
            i+=1
            frameCounter = 0
            showISI = True
    if showISI:
        text.setText(" ")
        frameCounter += 1
        if frameCounter == 72:
            frameCounter = 0
            showISI = False
else:
    continueRoutine = False

Thank you so much ajus, it works perfectly!!! Very elegant too!