所以,我想让python从列表中移植12次值(如下所示)。但是当它达到第12次洗牌时,它会无限延续。
for i in range(12):
entry.delete(0, tkinter.END)
random.shuffle(words)
label.config(text=str(words[1]))
scoreLabel.config(text="Time: " + str(score)+ "s")
另外,我试过这个但没有任何反应
if wordcount == '12':
scoreLabel.config(text="You did it in: " + str(score))
label.config(text="FINISHED")
如果有帮助,这就是wordcount链接的内容:
wordcount = 0
def nextWord():
global wordcount
entry.focus_set()
if entry.get().lower() == words[1].lower():
wordcount += 1
wordcounter.config(text="Words: " + str(wordcount))
这部分是问题所在,因为如果我交换它,它在运行时就不会做任何事情。 感谢。
我也试过了:
words = ["Games","Development","Keyboard","Speed","Typer","Anything","Alpha","Zealous","Accurate","Basics","Shortcut","Purpose","Window","Counter","Fortress","Modification","Computer","Science","History","Football","Basketball","Solid","Phantom","Battlefield","Advanced","Warfare","Download","Upload","Antidisestablishmentarianism","Supercalifragilisticexpialidocious","Discomobobulation","Liberated","Assassin","Brotherhood","Revelation","Unity","Syndicate","Victory"]
wordlist = len(words)
entry.delete(0, tkinter.END)
for i in range(12, wordlist):
#Tried with and without [i] below where using [i] throws the
TypeError: 'str' object does not support item assignment error
random.shuffle(words[i])
label.config(text=str(words[1]))
scoreLabel.config(text="Time: " + str(score)+ "s")
这不会起作用,因为它说:
TypeError: 'list' object is not callable
wordlist = words(range(12))
entry.delete(0, tkinter.END)
random.shuffle(wordlist)
label.config(text=str(words[1]))
scoreLabel.config(text="Time: " + str(score)+ "s")
另外我明白12意味着1,2,3,4,5等,但我不明白如何将其改组并显示12次。