python - python 中的 Stroop 测试无法正常工作。

标签 python testing matching

这是家庭作业:尝试在 Python 中创建 Stroop 测试。我已经写了大部分代码,但是我在制作匹配的刺激时遇到了麻烦 当我点击“下一步”按钮时,随机在不同和相同的刺激之间切换。

到目前为止,这是我的代码:

# Button, Label, Frame
from Tkinter import *
import random

def stimulus(same):
    colors = ['red', 'blue', 'green', 'yellow', 'orange', 'purple']

    word = random.choice(colors)
    if same == True:
        return (word, word)
    else:
        colors.remove(word)
        color = random.choice(colors)
        return (word, color)

# create label using stimulus
s = stimulus(same=True)

word, color = stimulus(True)
root = Tk()
label = Label(root, text=word, fg=color)
label.pack()

#create the window
def quit():
    root.destroy()
closebutton = Button(root, text = 'close', command=quit)
closebutton.pack(padx=50, pady=50)

def next():
    word, color = stimulus(True)
    label.congig(text=word, fg=color)
    label.update()

nextbutton = Button(root, text='next', comand=next)
nextbutton.pack()

root.mainloop()

最佳答案

您的问题的关键在于更改 next 按钮处理程序中的这一行:

word, color = stimulus(random.choice((True, False)))

但是,您的程序中有几个拼写错误导致它无法正常工作。 (还有一些重新定义的内置函数。)我在下面对其进行了修改:

import Tkinter  # Button, Label, Frame
import random

COLORS = ['red', 'blue', 'green', 'yellow', 'orange', 'purple']

def stimulus(same):
    colors = list(COLORS)

    word = random.choice(colors)

    if same:
        return (word, word)

    colors.remove(word)

    color = random.choice(colors)

    return (word, color)

def next_selected():
    word, color = stimulus(random.choice((True, False)))

    label.config(text=word, fg=color)

    label.update()

def quit_selected():
    root.destroy()

root = Tkinter.Tk()

# create the window

# create label using stimulus
word, color = stimulus(True)
label = Tkinter.Label(root, text=word, fg=color)
label.pack()

closebutton = Tkinter.Button(root, text='close', command=quit_selected)
closebutton.pack(padx=50, pady=50)

nextbutton = Tkinter.Button(root, text='next', command=next_selected)
nextbutton.pack()

root.mainloop()

关于python - python 中的 Stroop 测试无法正常工作。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36255642/

相关文章:

python - 检查可迭代列表中的 NoneTypes

python - Dask 从 HDFS 分发 : Reading . csv

c# - Python 到 C# 代码解释

testing - Jasmine .andCallFake 不触发 spineJs 的函数调用

Java:匹配具有未知字符的字符串的算法

r - 按向量 B 对命名向量 A 的值进行排序,但尽可能保持名称顺序

algorithm - 给定最大匹配找到二分图的最小顶点覆盖

python - 属性错误: 'OAndX' object has no attribute 'run'

testing - leiningen 测试数据的惯用路径

testing - 覆盖不完整的测试方法和模型是什么?