您好,我正在使用彩色Stroop,我可以使用代码更改单词和单词的颜色,但是当调用函数“ next_selected”时,我不能仅更改单词,有人可以帮我吗请 ?
def tick():
global doTick
global sec
if not doTick:
return
sec += 0.1
sec = round(sec, 1)
ftest1.after(100, tick)
time2Label.configure(text=sec)
if sec == 60.0:
doTick = False
time2Label.config(text=sec)
label1.config(text=score, fg='black')
def start():
global doTick
doTick = True
label1.pack()
tick()
startbutton1.destroy()
COLORS = ['blue','green','yellow','red']
def stimulus(same):
global word
colors = list(COLORS)
if same:
return (word)
colors.remove(word)
return (word)
def next_selected():
global word
word = stimulus(choice((True,False)))
label1.config(text=word)
label1.update()
stimulus()
当我们无法选择一种新的颜色时same=False
,也无法在全球范围内保存新的选择word
。试试看:
COLORS = ['blue', 'green', 'yellow', 'red']
word = COLORS[0]
def stimulus(same):
global word
if same: # return the previous color
return (word)
colors = list(COLORS)
colors.remove(word)
word = choice(colors) # chose a different color & remember it
return word
def next_selected():
global word
word = stimulus(choice((True, False)))
label1.config(text=word)
label1.update()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句