Skip to main content
 首页 » 编程设计

python之在 for 循环中多次呈现相同的 RatingScale

2024年11月24日17JustinYoung

我想在 for 循环中多次呈现相同的评分量表。

我试过这样做

for i in range(5): 
    while rating_scale.noResponse: 
        rating_question.draw() 
        rating_scale.draw() 
        win.flip() 
        if event.getKeys(['escape']): 
            core.quit() 

但它不会多次显示评分量表。它只是给出第一个循环的值 5 次。

所以,我想,如果我重新定义评分量表(我有两个 PsychoPy 可以选择的评分量表):

rating_question     = visual.TextStim(win, text = "Hoe moeilijk vond je deze trial?", pos = (0,0.5)) 
rating_scale_1      = visual.RatingScale(win, low=0, high=100, marker='slider', tickMarks=[0, 25, 50, 75, 100], stretch=2, tickHeight=1.5, labels=["Heel makkelijk", "Makkelijk", "Neutraal", "Moeilijk", "Heel moeilijk"], showValue=False) 
rating_scale_2      = visual.RatingScale(win, low=0, high=100, marker='slider', tickMarks=[0, 25, 50, 75, 100], stretch=2, tickHeight=1.5, labels=["Heel moeilijk", "Moeilijk", "Neutraal", "Makkelijk", "Heel makkelijk"], showValue=False) 
rating_scales       = [rating_scale_1, rating_scale_2] 
 
for i in range(5): 
    rating_scale = rating_scales[random.randint(0,2)] 
    while rating_scale.noResponse: 
        rating_question.draw() 
        rating_scale.draw() 
        win.flip() 
        if event.getKeys(['escape']): 
            core.quit() 

但这会产生错误,因为我假设它会自动选择相同的评分量表 5 次。因此,当随机整数在后续循环中不同时,它就不起作用。

所以,然后我就这样尝试了,但它与代码的第一部分一样。仍然只有一个评级量表的呈现和相同值的 5 倍。

for i in range(5): 
    rating_scale = rating_scales[1] 
    while rating_scale.noResponse: 
        rating_question.draw() 
        rating_scale.draw() 
        win.flip() 
        if event.getKeys(['escape']): 
            core.quit() 

我知道它为什么会发生(因为我说只有在没有响应时才需要出现循环),但我不知道如何解决它。据我所知,评分量表与 .clear() 属性完全不同。

请您参考如下方法:

您需要在一个响应和下一个响应之间采取一些操作,例如:

for trial in trials: 
 
    # update the question for this trial: 
    rating_question.text = trial['question'] 
 
    # present the rating scale:         
    while rating_scale.noResponse: 
        rating_question.draw() 
        rating_scale.draw() 
        win.flip() 
        if event.getKeys(['escape']): 
            core.quit() 
 
    # a response was made, so save it on each iteration 
    trials.addData('rating.response', rating.getRating()) 
    trials.addData('rating.rt', rating.getRT()) 
 
    # reset the scale to its original state for the next iteration: 
    rating_scale.reset() 

上面,trials 表示您用来控制试验的 TrialHandler 处理程序对象。