dimanche 27 mars 2016

Stroop test in python not working properly.

This is homework: trying to create a Stroop test in python. I have written most of the code already, but i'm having trouble making the matching stimuli randomly switch between different and same stimuli when I hit the 'next' button.

Here's my code so far:

# 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()

Aucun commentaire:

Enregistrer un commentaire