One question about win.flip()

Is it possible in Psychopy to keep old images on the screen and new ones to be rendered late? I used to program PyGame and found that I could do this, but now I can’t find this method with Psychopy programming.Win.flip () refreshes the entire interface, not individual objects or locations. So can we do that with Psychopy?

win.flip(clearBuffer = False)

https://www.psychopy.org/api/visual/window.html#psychopy.visual.Window.flip

but there probably aren’t many uses for this. Setting the .autoDraw attribute of your individual stimuli might better achieve what you want.

1 Like

Thank you a lot,and I can’t wait to try it,but my computer is not with me now.

图片 图片
first pic code represent old object,and second pic code represent new object,but " the TypeError: ‘attributeSetter’ object is not callable " in the end.

I’m so confused.

Hi,

It should probably be:

tar_stim.autoDraw = True

i.e. no brackets are needed.

PS for future posts, please provide your code as complete text rather than images (especially cropped images) - it makes it much easier to copy and paste suggestions from your post.

There is another question that how to clear the last trial all pics, in other words, I just want to old pics autodraw in an internal trial when codes run in the next trial all pics clear? Thanks for your help and patience.

Sorry, I don’t quite understand what you want to do. Could you break down the description into many more explicit steps?


I want the red bar to appear 100ms after others, and figure 1(first trial)meets my requirement, but other color bars will overlap in the next like figure 2(2nd trial), that is, the blue bars of the first trial are not cleaned.

It’s hard to know without seeing your code. This could be a result of not clearing the auto draw setting of some stimuli, or not clearing the buffer on your last win.flip().

We really need to see a (minimal) example of your code to see what is going on.

    for i in range(t):
        x = ls_randx[0]
        y = ls_randy[0]
        X = cell_w * x + x4
        Y = cell_w * y + y4
        jiaodu = random.choice(jiaodulist)
        tar_stim1 = visual.ImageStim(win, image='蓝.png', pos=(X, Y), ori='0')
        tar_stim1.autoDraw = True         
    # normal
    s = random.randint(t + d, 6)
    for i in range(t + d, s + 1):
        x = ls_randx[i]
        y = ls_randy[i]
        X = cell_w * x + x1
        Y = cell_w * y + y1
        jiaodu = random.choice(jiaodulist)
        tar_stim2 = visual.ImageStim(win, image='蓝.png', pos=(X, Y), ori=jiaodu)
        tar_stim2.autoDraw = True
        # win.flip()
    for i in range(s + 1, 8):
        x = ls_randx[i]
        y = ls_randy[i]
        X = cell_w * x + x1
        Y = cell_w * y + y1
        jiaodu = random.choice(jiaodulist)
        tar_stim3 = visual.ImageStim(win, image='蓝.png', pos=(X, Y), ori=jiaodu)
        tar_stim3.autoDraw = True
        win.flip()
        
        
    win.flip()
        # salient
    for i in range(d):
        x = ls_randx[1]
        y = ls_randy[1]
        X = cell_w * x + x3
        Y = cell_w * y + y3
        jiaodu = random.choice(jiaodulist)
        tar_stim = visual.ImageStim(win, image='红色干扰.png', pos=(X, Y), ori=jiaodu)
        tar_stim.draw()
        core.wait(0.100)
    win.flip()
    
   
Rtime.reset()
tar_resp = event.waitKeys(maxsize, ['z', 'slash'])
Rt = Rtime.getTime()
win.setColor(gray)
win.flip()

I think the question is that how to clear the buffer.

An extra win.flip() will clear the buffer (at the cost of a frame)

This is an internal loop function and wherever I add win. flip(), it does not work.

I don’t think this code is doing what is intended. Do you see how, despite being embedded in a loop, only one stimulus will be exist at the end of it (tar_stim1), yet it has been instantiated multiple times for no apparent purpose (and this will be slow and time-consuming, when instead, it could have just been created once).

  • What is the above code intended to do?
  • What does t represent?

I guess we need to establish that before going further into the code.

if t==0 and d==1:#no target , one salience dis
    
    # normal dis
    s = random.randint(1, 6)
    for i in range(1, s + 1):
        x = ls_randx[i]
        y = ls_randy[i]
        X = cell_w * x+x1
        Y =  cell_w * y+y1
        jiaodu = random.choice(jiaodulist)
        tar_stim1= visual.ImageStim(win, image='蓝.png', pos=(X, Y), ori=jiaodu)
        # tar_stim.draw()
        tar_stim1.autoDraw=True
        # win.flip()

    for i in range(s + 1, 8):
        x = ls_randx[i]
        y = ls_randy[i]
        X = cell_w * x+x2
        Y = cell_w * y+y2
        jiaodu = random.choice(jiaodulist)
        tar_stim2 = visual.ImageStim(win, image='蓝.png', pos=(X, Y), ori=jiaodu)
        # tar_stim2.autoDraw=True
        tar_stim2.autoDraw=True
        # win.flip()
    win.flip()
    core.wait(0.100)
    # 凸显干扰
    for i in range(1):
        x = ls_randx[0]
        y = ls_randy[0]
        X = cell_w * x+x3
        Y = cell_w * y+y3
        jiaodu = random.choice(jiaodulist)
        tar_stim = visual.ImageStim(win, image='红色干扰.png', pos=(X, Y), ori=jiaodu)
        tar_stim.draw()
        # core.wait(0.100)
    win.flip()

else:
    for i in range(t):
        x = ls_randx[0]
        y = ls_randy[0]
        X = cell_w * x + x4
        Y = cell_w * y + y4
        jiaodu = random.choice(jiaodulist)
        tar_stim1 = visual.ImageStim(win, image='蓝.png', pos=(X, Y), ori='0')
        tar_stim1.autoDraw = True
    # 一般干扰
    s = random.randint(t + d, 6)
    for i in range(t + d, s + 1):
        x = ls_randx[i]
        y = ls_randy[i]
        X = cell_w * x + x1
        Y = cell_w * y + y1
        jiaodu = random.choice(jiaodulist)
        tar_stim2 = visual.ImageStim(win, image='蓝.png', pos=(X, Y), ori=jiaodu)
        tar_stim2.autoDraw = True
        # win.flip()
    for i in range(s + 1, 8):
        x = ls_randx[i]
        y = ls_randy[i]
        X = cell_w * x + x1
        Y = cell_w * y + y1
        jiaodu = random.choice(jiaodulist)
        tar_stim3 = visual.ImageStim(win, image='蓝.png', pos=(X, Y), ori=jiaodu)
        tar_stim3.autoDraw = True
        win.flip()
    win.flip()
    core.wait(0.100)
        # 凸显干扰
    for i in range(d):
        x = ls_randx[1]
        y = ls_randy[1]
        X = cell_w * x + x3
        Y = cell_w * y + y3
        jiaodu = random.choice(jiaodulist)
        tar_stim = visual.ImageStim(win, image='红色干扰.png', pos=(X, Y), ori=jiaodu)
        tar_stim.draw()
        # core.wait(0.100)
    win.flip()

t presents target number and d present dis num.