2015-10-04 39 views
-1

由于某些原因,尽管事实上它从字符串中取出的列表与颜色无关,但Python仍然会在“未知颜色”的位置抛出TCL错误。这有什么理由吗?Python误解了我的列表

#Add words to this list to include them in the game 
words = ["Games","Development","Keyboard","Speed","Typer","Anything","Aplha","Zealous","Accurate","Basics","Shortcut","Purpose","Window","Counter","Fortress","Modification","Computer","Science","History","Football","Basketball","Solid","Phantom","Battlefield","Avdvanced","Warfare","Download","Upload","Antidisestablishmentarianism","Supercalifragilisticexpialidocious","Discomobobulation","Liberated","Assassin","Brotherhood","Revelation","Unity","Syndicate","Victory"] 

def nextWord(): 
     global score 
     entry.focus_set() 
     if entry.get().lower() == words[1].lower(): 
      score += 1 

     entry.delete(0, tkinter.END) 
     random.shuffle(words) 
     label.config(fg=str(words[1]), text=str(words[0])) 
     scoreLabel.config(text="Score: " + str(score)) 

这是新的错误:

ValueError: dictionary update sequence element #0 has length 1; 2 is required 

而且,我知道有些/大多数我的代码也许不正确的,我想知道如何设置的次最高金额洗牌并且在打印它们在标签中通过它们所花费的时间之前显示一个字符串。 (次要问题,不必回答,如果你不想) 谢谢。

+0

如果您收到异常,请发布堆栈跟踪,并确定哪条线路导致问题。 – khelwood

+0

对不起,我是新来的,但我已经改变了它 – Ernxst

回答

1

你明确地告诉tkinter尽可能使用单词作为颜色;这就是fglabel.config(fg=str(words[1]),...)行中所做的。

由于它不是一种颜色,你不应该那样做。

+0

那么有什么我可以用来修复它或只是删除fg = str? – Ernxst

+0

我不明白你在做什么。是的,显然你应该删除它,如果你不想设置颜色。 –

+0

我试图从列表中获得随机单词并显示在标签中,但我已将其删除但它引发了值错误 – Ernxst