2016-05-09 9 views
-4

こんにちは私は色のストロープに関する作業をしています。自分のコードで単語の色と色を変更できます。しかし、私の関数 "next_selected"が呼び出されたときに言葉だけを変更することはできません。リストからの単語のランダムな選択が正しく機能しない(Python/Tkinter)

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() 
+1

なぜあなたはそれを変更できませんか?試してみるとどうなりますか? –

+0

何も表示されません。コンソールは正しい単語かどうかを知っていますが、その次のランダムな単語は機能しません(私の英語には申し訳ありません) –

+0

私はちょうどそれを作る方法がわかりません、私はPythonの新機能です –

答えて

0

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() 
+0

ありがとう、これは完璧に機能しました!私のカラーストロボテストの作品は知っている:) –

関連する問題