【发布时间】:2017-02-18 21:38:14
【问题描述】:
我从 usingpython.com 获得此代码,这是一个“输入颜色而不是单词”game。
我正在使用此代码来构建此游戏的改进版本,但出现了问题,我不知道为什么。
所以,当倒计时为 0 时,我想将单词所在的标签(名为“标签”)更改为“游戏结束!你的分数是 bla bla bla”。所以,我这样做了(我添加的只是最后两行):
def nextColour():
#use the globally declared 'score' and 'play' variables above.
global score
global timeleft
#if a game is currently in play...
if timeleft > 0:
#...make the text entry box active.
e.focus_set()
#if the colour typed is equal to the colour of the text...
if e.get().lower() == colours[1].lower():
#...add one to the score.
score += 1
#clear the text entry box.
e.delete(0, tkinter.END)
#shuffle the list of colours.
random.shuffle(colours)
#change the colour to type, by changing the text _and_ the colour to a random colour value
label.config(fg=str(colours[1]), text=str(colours[0]))
#update the score.
scoreLabel.config(text="Score: " + str(score))
elif timeleft == 0:
ĺabel.config(text="Game Over! Your score is: " + score)
这不起作用。当倒计时为 0 时,游戏什么也不做并停止。
我在想我是否可以用一个while循环来做到这一点......
【问题讨论】: