【问题标题】:Bad Color String Error in Python Using Turtle使用 Turtle 在 Python 中出现错误的颜色字符串错误
【发布时间】:2016-11-30 20:13:41
【问题描述】:

在我的 python 程序中,我正在读取文件并将内容存储在列表中。我检查了列表的每个索引,所以我知道它存储正确。 然后我将一个特定的索引传递给一个包含蓝色的类。 每当它到达turtle.color我得到一个错误bad color string: "blue"

例如: Team = Rainbow(str(sequence[0]),str(sequence[1]), str(sequence[2])) //index 2 (str(sequence[2])) contains "blue"

我有一堂课

class Rainbow:
    def __init__(self, Rname, Rteam, Rcolor):
       self.name = Rname
       self.team = Rteam
       self.color = Rcolor

       self.Rturtle = turtle.Turtle()

       self.Rturtle.color(self.color)//here is where I get the error

我确保所有内容都正确导入,并对这个错误进行了一些研究,只遇到了错误序列的问题。另外,如果我通过Team = Rainbow("Jay","Blue Jays","blue")我不会得到错误。

我想知道是否有人可以提供帮助

【问题讨论】:

    标签: python python-3.x colors turtle-graphics


    【解决方案1】:

    这可能是因为您的颜色字​​符串还包含不需要的空格。例如将第 3 行更改为 self.color = Rcolor.strip() 以查看它是否解决了问题。

    【讨论】:

    • 碰巧有一个空白问题,但我不得不修复文本文件,因为 .strip() 不起作用
    • 我在 Python 2 中遇到了同样的错误,例如笔色('红色')。在 Python 3 中工作。
    猜你喜欢
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 2014-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多