gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:27:23 24 4
gpt4 key购买 nike

这是家庭作业:尝试在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com