| Reference | Downloads | Github

Psychopy window clearing

Hi everyone, if I want to rerun the experiment on the same window, is there any way(python logic) to restart the experiment on the same window by clearing the past stimulus shapes, instead of closing it and creating new window??

It is a bit difficult to suggest a tailored solution without having a glimpse of how you go about coding the part where you present your stimuli. I have done something like this before, and it goes something along the lines of:-

TrialList = [.....list of randomly shuffled variables for each trial....] # let's assume I have 100 items/trials in this list

trialnum = 0 # counter for trials

# This gets my experiment to run twice the length of my original TrialList because I want to re-run it the second time, thus multiplying the range of the length of my TrialList by 2.

for experiment in range(len(TrialList)*2):
    if TrialList[trialnum] == 'hello':
    .... all your experiment codes....

    # At the end of each trial
    trialnum += 1
    # Flip to clear everything on screen

    # If trialnum reaches the end of the TrialList
    if trialnum == 100:
        trialnum = 0 # this resets trialnum to load first item of my trial list on the next loop.

I’m afraid the description of your problem is too imprecise: What do you mean by “rerun the experiment”? Running a second block with the same trials but in different order? You probably don’t want to show a welcome message and detailed instructions twice which would happen if you rerun the whole experiment!?

yes @mario.reutter, the procedure to run tobii experiment is in 3 steps as follows,

  1. fixing eye position,
  2. Calibration,
  3. Running real time experiment

As mentioned above, every time, before I start experiment i should start from 1 st step, so its taking lot of time to run the expereiment. So i am trying to skip the 1 and 2 steps to run the experiment again and again. I wrote a snippet of code that gives 2 options to the user i.e 1st option is quitting the experiment by giving ‘esc’ key and 2nd option is to run the experiment again by giving ‘a’ key. If observer presses key ‘a’ the experiment should reset and should start the 3 step again. I am able to do repeat the experiment , but I am not able to clear the shapes that were created in the past experiment as those shapes are continued to shown.
So here my showstopper is clearing the shapes on the window.
I hope you understood my point, still if you feel anything missed from information let me know. thank you.

Ah ok. If I understand you correclty, one misunderstanding seems to be that you chose the category of this topic to be “Coding” but you created your experiment in Builder - is that correct?

I’m not familiar with Builder but it seems like you marked your shapes to have “auto draw” enabled, i.e. they will be shown automatically on the screen.
You can either change this such that the shapes are only drawn once or you could create another code snippet at the beginning of part 3 that calls for every shape: shapename.setAutoDraw(False).

I hope this solves your problem.