psychopy coder模式編寫心理試驗程序 圖片呈現和量表評分

呈現圖片

準備一張圖片和一個python文件,以下圖:python

python文件中寫以下代碼:dom

# -*- coding: utf-8 -*-
"""
Created on Tue Apr 12 10:31:15 2016

@author: zbg
"""

from psychopy.visual import Window, ImageStim, TextStim
from psychopy import core, event, gui
import random

name='1.png'
win = Window()
stim = ImageStim(win, name)
stim.draw()
texture = TextStim(win, text = u'按空格鍵退出', pos = [0,30], units = 'pix')
texture.draw()
win.flip()

while 'space' not in event.getKeys():
    pass
win.close()

運行後能夠呈現圖片工具

量表評分

編寫以下程序能夠實現量表評分ui

# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 16:50:21 2015

@author: zbg
"""

from psychopy.visual import Window, ImageStim, TextStim
from psychopy import core, event, gui
import random

scales = [
         ('Meaningful1', u"我能理解這幅畫的意義"),
         ('Meaningful2', u"我能理解這幅畫的主題"),
         ('Unity',       u"這幅畫的構圖是和諧統一的"),
         ('Complexity',  u"這幅畫的構圖是複雜的"),
         ('Variety',     u"這幅畫構圖是多樣的"),
         ('Liking',      u"我喜歡這幅畫"),
         ('Pleasing',    u"這幅畫使我感到愉悅"),
         ('Interesting', u"這幅畫能引發個人興趣。"),
        ]
        

def ShowScale(text):
    def GetMyKey():
        event.clearEvents1('all')
        keys=[]
        while True:
            while len(keys) == 0:
                core.wait(0.1)
                keys=event.getKeys()
            
            if keys[0] in ['1', '2', '3', '4', '5', '6', '7']:
                return keys[0]
            
            keys = []
    
    t =TextStim(win, text ,pos=(0,-0.0))
    t.draw()
    t =TextStim(win, u'1不一樣意------------------------------7很是贊成',pos=(0,-50), units = 'pix')
    t.draw()
    win.flip()
            
    key = GetMyKey()
    
    t =TextStim(win, u'你按下了' + key,pos=(0,-0.2),color = (0 ,1.,0))#反饋
    t.draw()
    win.flip()
    core.wait(0.5)
    
    return key
    
win = Window()

result = {}
for label, text in scales:
    key = ShowScale(text)
    result[label] = key #把結果儲存到字典裏,後繼能夠保存到文件裏。

win.close()
print result

把兩個程序合在一塊兒能夠實現呈現圖片,而後用量表評分,這裏不作贅述。spa

psychopy自帶的量表工具

你也能夠使用psychopy自帶的量表工具,它支持鼠標選擇或者按鍵數字選擇,用回車鍵確認或者鼠標點擊方框確認。如下是示例代碼與運行截圖:.net

# -*- coding: utf-8 -*-
"""
Created on Tue Apr 12 10:31:15 2016

@author: zbg
"""
from psychopy import visual,event

win = visual.Window()
rating = visual.RatingScale(win=win, name='rating', marker=u'triangle',
size=1.5, pos=[0.0, -0.4], low=1, high=7, labels=[u'不一樣意', u'中立', u'徹底贊成'],
scale=u'你多大程度上贊同希拉里當選美國總統?')
#item = <statement, question, image, movie, ...>
while rating.noResponse:
    #item.draw()
    rating.draw()
    win.flip()
    
visual.TextStim(win, text = u"選了%d用了%.3f秒\n按空格退出" % (rating.getRating(), rating.getRT())).draw()
win.flip()

while 'space' not in event.getKeys():
    pass
    
print  rating.getRating()
print  rating.getRT()
print  rating.getHistory()

其餘

另有一個完整的多種圖片與量表評分的示例,完整程序(包括圖片等文件)見:http://download.csdn.net/detail/zhanghao9547/8618453 或 http://vdisk.weibo.com/s/uu-WVvhhP2V2arest

psychopy 定作實驗程序 https://item.taobao.com/item.htm?spm=a230r.1.14.6.Q6E2OW&id=530690095131&ns=1&abbucket=15#detailcode

相關文章
相關標籤/搜索