How to unable keyboard response for a determined time if correct/incorrect response?

OS: OS X
PsychoPy version: 1.3

What are you trying to achieve?:
In my experiment we present four stimuli with one corresponding response each one. I’m trying to unable keyboard responses for a second if their last response was incorrect. They cannot go to the next trial if they didn’t give the correct response. If their answer was correct there is a delay of 0.3s for the next trial.
What did you try to make it work?:
I tried to created a variable for allowed_keys and change it with a conditional and clock element. The problem is that in the builder allowed_keys component is constant and I cannot change it Each Frame. I also tried to play with stop and expected duration elements of keyboard component but I’m quite new in psychopy and I don’t know if it works.

This is what I’m trying but it doesn’t work:

#Begin Routine
delay_timer = core.Clock()
LastKey = key_resp.keys
NErrors = 0

#Each Frame

#Continue the routine only after correct response and delay for incorrect
if len(key_resp.keys) > 0 and LastKey[-1] == hand_response:
    key_resp.corr = True
    continueRoutine = False
elif len(key_resp.keys) > 0 and LastKey[-1] != hand_response:
    key_resp.corr = False
    continueRoutine = True
    delay_timer.reset()
    NErrors +=1
    LastKey = ()
if delay_timer.getTime() >= 1:
    LastKey = key_resp.keys [-1]